
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/core.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:09 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Core &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="core.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Cryptography" href="crypto.html" />
    <link rel="prev" title="Concrete" href="concrete.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="crypto.html" title="Cryptography"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="concrete.html" title="Concrete"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Core</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="core">
<h1>Core<a class="headerlink" href="#core" title="Permalink to this headline">¶</a></h1>
<section id="module-sympy.core.sympify">
<span id="sympify"></span><h2>sympify<a class="headerlink" href="#module-sympy.core.sympify" title="Permalink to this headline">¶</a></h2>
<section id="id1">
<h3>sympify<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.sympify.sympify">
<span class="sig-prename descclassname"><span class="pre">sympy.core.sympify.</span></span><span class="sig-name descname"><span class="pre">sympify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">convert_xor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/sympify.py#L92-L476"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.sympify.sympify" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an arbitrary expression to a type that can be used inside SymPy.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>a :</strong></p>
<blockquote>
<div><ul class="simple">
<li><p>any object defined in SymPy</p></li>
<li><p>standard numeric python types: int, long, float, Decimal</p></li>
<li><p>strings (like “0.09”, “2e-19” or ‘sin(x)’)</p></li>
<li><p>booleans, including <code class="docutils literal notranslate"><span class="pre">None</span></code> (will leave <code class="docutils literal notranslate"><span class="pre">None</span></code> unchanged)</p></li>
<li><p>dict, lists, sets or tuples containing any of the above</p></li>
</ul>
</div></blockquote>
<p><strong>convert_xor</strong> : boolean, optional</p>
<blockquote>
<div><p>If true, treats XOR as exponentiation.
If False, treats XOR as XOR itself.
Used only when input is a string.</p>
</div></blockquote>
<p><strong>locals</strong> : any object defined in SymPy, optional</p>
<blockquote>
<div><p>In order to have strings be recognized it can be imported
into a namespace dictionary and passed as locals.</p>
</div></blockquote>
<p><strong>strict</strong> : boolean, optional</p>
<blockquote>
<div><p>If the option strict is set to True, only the types for which
an explicit conversion has been defined are converted. In the
other cases, a SympifyError is raised.</p>
</div></blockquote>
<p><strong>rational</strong> : boolean, optional</p>
<blockquote>
<div><p>If true, converts floats into Rational.
If false, it lets floats remain as it is.
Used only when input is a string.</p>
</div></blockquote>
<p><strong>evaluate</strong> : boolean, optional</p>
<blockquote>
<div><p>If False, then arithmetic and operators will be converted into
their SymPy equivalents. If True the expression will be evaluated
and the result will be returned.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>It will convert Python ints into instances of sympy.Integer,
floats into instances of sympy.Float, etc. It is also able to coerce symbolic
expressions which inherit from Basic. This can be useful in cooperation
with SAGE.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Note that this function uses <code class="docutils literal notranslate"><span class="pre">eval</span></code>, and thus shouldn’t be used on
unsanitized input.</p>
</div>
<p>If the argument is already a type that SymPy understands, it will do
nothing but return that value. This can be used at the beginning of a
function to ensure you are working with the correct type.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sympify</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">is_integer</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;2.0&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;2e-45&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
</pre></div>
</div>
<p>If the expression could not be converted, a SympifyError is raised.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;x***2&quot;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">SympifyError</span>: <span class="n">SympifyError: &quot;could not parse &#39;x***2&#39;&quot;</span>
</pre></div>
</div>
<p class="rubric">Locals</p>
<p>The sympification happens with access to everything that is loaded
by <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">sympy</span> <span class="pre">import</span> <span class="pre">*</span></code>; anything used in a string that is not
defined by that import will be converted to a symbol. In the following,
the <code class="docutils literal notranslate"><span class="pre">bitcount</span></code> function is treated as a symbol and the <code class="docutils literal notranslate"><span class="pre">O</span></code> is
interpreted as the Order object (used with series) and it raises
an error when used improperly:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;bitcount(42)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">bitcount(42)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;O(x)&quot;</span><span class="p">)</span>
<span class="go">O(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;O + 1&quot;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">unbound method...</span>
</pre></div>
</div>
<p>In order to have <code class="docutils literal notranslate"><span class="pre">bitcount</span></code> be recognized it can be imported into a
namespace dictionary and passed as locals:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ns</span> <span class="o">=</span> <span class="p">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exec</span><span class="p">(</span><span class="s1">&#39;from sympy.core.evalf import bitcount&#39;</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="nb">locals</span><span class="o">=</span><span class="n">ns</span><span class="p">)</span>
<span class="go">6</span>
</pre></div>
</div>
<p>In order to have the <code class="docutils literal notranslate"><span class="pre">O</span></code> interpreted as a Symbol, identify it as such
in the namespace dictionary. This can be done in a variety of ways; all
three of the following are possibilities:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ns</span><span class="p">[</span><span class="s2">&quot;O&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;O&quot;</span><span class="p">)</span>  <span class="c1"># method 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exec</span><span class="p">(</span><span class="s1">&#39;from sympy.abc import O&#39;</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span>  <span class="c1"># method 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ns</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">O</span><span class="o">=</span><span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;O&quot;</span><span class="p">)))</span>  <span class="c1"># method 3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s2">&quot;O + 1&quot;</span><span class="p">,</span> <span class="nb">locals</span><span class="o">=</span><span class="n">ns</span><span class="p">)</span>
<span class="go">O + 1</span>
</pre></div>
</div>
<p>If you want <em>all</em> single-letter and Greek-letter variables to be symbols
then you can use the clashing-symbols dictionaries that have been defined
there as private variables: _clash1 (single-letter variables), _clash2
(the multi-letter Greek names) or _clash (both single and multi-letter
names that are defined in abc).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">_clash1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">set</span><span class="p">(</span><span class="n">_clash1</span><span class="p">)</span>
<span class="go">{&#39;E&#39;, &#39;I&#39;, &#39;N&#39;, &#39;O&#39;, &#39;Q&#39;, &#39;S&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;I &amp; Q&#39;</span><span class="p">,</span> <span class="n">_clash1</span><span class="p">)</span>
<span class="go">I &amp; Q</span>
</pre></div>
</div>
<p class="rubric">Strict</p>
<p>If the option <code class="docutils literal notranslate"><span class="pre">strict</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, only the types for which an
explicit conversion has been defined are converted. In the other
cases, a SympifyError is raised.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">sympify</span><span class="p">(</span><span class="kc">None</span><span class="p">))</span>
<span class="go">None</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">SympifyError</span>: <span class="n">SympifyError: None</span>
</pre></div>
</div>
<p class="rubric">Evaluation</p>
<p>If the option <code class="docutils literal notranslate"><span class="pre">evaluate</span></code> is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, then arithmetic and
operators will be converted into their SymPy equivalents and the
<code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> option will be added. Nested <code class="docutils literal notranslate"><span class="pre">Add</span></code> or <code class="docutils literal notranslate"><span class="pre">Mul</span></code> will
be denested first. This is done via an AST transformation that replaces
operators with their SymPy equivalents, so if an operand redefines any
of those operations, the redefined operators will not be used. If
argument a is not a string, the mathematical expression is evaluated
before being passed to sympify, so adding evaluate=False will still
return the evaluated result of expression.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;2**2 / 3 + 5&#39;</span><span class="p">)</span>
<span class="go">19/3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;2**2 / 3 + 5&#39;</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">2**2/3 + 5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;4/2+7&#39;</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">9</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;4/2+7&#39;</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">4/2 + 7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="mi">4</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="mi">7</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">9.00000000000000</span>
</pre></div>
</div>
<p class="rubric">Extending</p>
<p>To extend <code class="docutils literal notranslate"><span class="pre">sympify</span></code> to convert custom objects (not derived from <code class="docutils literal notranslate"><span class="pre">Basic</span></code>),
just define a <code class="docutils literal notranslate"><span class="pre">_sympy_</span></code> method to your class. You can do that even to
classes that you do not own by subclassing or adding the method at runtime.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyList1</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="mi">1</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="mi">2</span>
<span class="gp">... </span>        <span class="k">return</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span> <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="p">)[</span><span class="n">i</span><span class="p">]</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_sympy_</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="n">Matrix</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="n">MyList1</span><span class="p">())</span>
<span class="go">Matrix([</span>
<span class="go">[1],</span>
<span class="go">[2]])</span>
</pre></div>
</div>
<p>If you do not have control over the class definition you could also use the
<code class="docutils literal notranslate"><span class="pre">converter</span></code> global dictionary. The key is the class and the value is a
function that takes a single argument and returns the desired SymPy
object, e.g. <code class="docutils literal notranslate"><span class="pre">converter[MyList]</span> <span class="pre">=</span> <span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">Matrix(x)</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyList2</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>   <span class="c1"># XXX Do not do this if you control the class!</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>  <span class="c1">#     Use _sympy_!</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="mi">1</span>
<span class="gp">... </span>        <span class="k">yield</span> <span class="mi">2</span>
<span class="gp">... </span>        <span class="k">return</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span> <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="p">)[</span><span class="n">i</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.sympify</span> <span class="kn">import</span> <span class="n">converter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">converter</span><span class="p">[</span><span class="n">MyList2</span><span class="p">]</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">Matrix</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="n">MyList2</span><span class="p">())</span>
<span class="go">Matrix([</span>
<span class="go">[1],</span>
<span class="go">[2]])</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The keywords <code class="docutils literal notranslate"><span class="pre">rational</span></code> and <code class="docutils literal notranslate"><span class="pre">convert_xor</span></code> are only used
when the input is a string.</p>
<p class="rubric">Convert_xor</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;x^y&#39;</span><span class="p">,</span><span class="n">convert_xor</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;x^y&#39;</span><span class="p">,</span><span class="n">convert_xor</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x ^ y</span>
</pre></div>
</div>
<p class="rubric">Rational</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;0.1&#39;</span><span class="p">,</span><span class="n">rational</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">0.1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="s1">&#39;0.1&#39;</span><span class="p">,</span><span class="n">rational</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">1/10</span>
</pre></div>
</div>
<p>Sometimes autosimplification during sympification results in expressions
that are very different in structure than what was entered. Until such
autosimplification is no longer done, the <code class="docutils literal notranslate"><span class="pre">kernS</span></code> function might be of
some use. In the example below you can see how an expression reduces to
-1 by autosimplification, but does not do so when <code class="docutils literal notranslate"><span class="pre">kernS</span></code> is used.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.sympify</span> <span class="kn">import</span> <span class="n">kernS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="o">-</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)))</span> <span class="o">-</span> <span class="mi">1</span>
<span class="go">-1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;-2*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x))) - 1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">-1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">kernS</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">-2*(-(-x + 1/x)/(x*(x - 1/x)**2) - 1/(x*(x - 1/x))) - 1</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.assumptions">
<span id="assumptions"></span><h2>assumptions<a class="headerlink" href="#module-sympy.core.assumptions" title="Permalink to this headline">¶</a></h2>
<p>This module contains the machinery handling assumptions.</p>
<p>All symbolic objects have assumption attributes that can be accessed via
.is_&lt;assumption name&gt; attribute.</p>
<p>Assumptions determine certain properties of symbolic objects and can
have 3 possible values: True, False, None.  True is returned if the
object has the property and False is returned if it doesn’t or can’t
(i.e. doesn’t make sense):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">is_algebraic</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">is_prime</span>
<span class="go">False</span>
</pre></div>
</div>
<p>When the property cannot be determined (or when a method is not
implemented) None will be returned, e.g. a generic symbol, x, may or
may not be positive so a value of None is returned for x.is_positive.</p>
<p>By default, all symbolic values are in the largest set in the given context
without specifying the property. For example, a symbol that has a property
being integer, is also real, complex, etc.</p>
<p>Here follows a list of possible assumption names:</p>
<dl class="glossary simple">
<dt id="term-commutative">commutative<a class="headerlink" href="#term-commutative" title="Permalink to this term">¶</a></dt><dd><p>object commutes with any other object with
respect to multiplication operation.</p>
</dd>
<dt id="term-complex">complex<a class="headerlink" href="#term-complex" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of complex numbers.</p>
</dd>
<dt id="term-imaginary">imaginary<a class="headerlink" href="#term-imaginary" title="Permalink to this term">¶</a></dt><dd><p>object value is a number that can be written as a real
number multiplied by the imaginary unit <code class="docutils literal notranslate"><span class="pre">I</span></code>.  See
<a class="reference internal" href="#r94" id="id2"><span>[R94]</span></a>.  Please note that <code class="docutils literal notranslate"><span class="pre">0</span></code> is not considered to be an
imaginary number, see
<a class="reference external" href="https://github.com/sympy/sympy/issues/7649">issue #7649</a>.</p>
</dd>
<dt id="term-real">real<a class="headerlink" href="#term-real" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of real numbers.</p>
</dd>
<dt id="term-integer">integer<a class="headerlink" href="#term-integer" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of integers.</p>
</dd>
<dt id="term-odd">odd<a class="headerlink" href="#term-odd" title="Permalink to this term">¶</a></dt><dt id="term-even">even<a class="headerlink" href="#term-even" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set of
odd (even) integers <a class="reference internal" href="#r93" id="id3"><span>[R93]</span></a>.</p>
</dd>
<dt id="term-prime">prime<a class="headerlink" href="#term-prime" title="Permalink to this term">¶</a></dt><dd><p>object is a natural number greater than <code class="docutils literal notranslate"><span class="pre">1</span></code> that has
no positive divisors other than <code class="docutils literal notranslate"><span class="pre">1</span></code> and itself.  See <a class="reference internal" href="#r97" id="id4"><span>[R97]</span></a>.</p>
</dd>
<dt id="term-composite">composite<a class="headerlink" href="#term-composite" title="Permalink to this term">¶</a></dt><dd><p>object is a positive integer that has at least one positive
divisor other than <code class="docutils literal notranslate"><span class="pre">1</span></code> or the number itself.  See <a class="reference internal" href="#r95" id="id5"><span>[R95]</span></a>.</p>
</dd>
<dt id="term-zero">zero<a class="headerlink" href="#term-zero" title="Permalink to this term">¶</a></dt><dd><p>object has the value of <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
</dd>
<dt id="term-nonzero">nonzero<a class="headerlink" href="#term-nonzero" title="Permalink to this term">¶</a></dt><dd><p>object is a real number that is not zero.</p>
</dd>
<dt id="term-rational">rational<a class="headerlink" href="#term-rational" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of rationals.</p>
</dd>
<dt id="term-algebraic">algebraic<a class="headerlink" href="#term-algebraic" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of algebraic numbers <a class="footnote-reference brackets" href="#id14" id="id6">11</a>.</p>
</dd>
<dt id="term-transcendental">transcendental<a class="headerlink" href="#term-transcendental" title="Permalink to this term">¶</a></dt><dd><p>object can have only values from the set
of transcendental numbers <a class="footnote-reference brackets" href="#id13" id="id7">10</a>.</p>
</dd>
<dt id="term-irrational">irrational<a class="headerlink" href="#term-irrational" title="Permalink to this term">¶</a></dt><dd><p>object value cannot be represented exactly by Rational, see <a class="reference internal" href="#r96" id="id8"><span>[R96]</span></a>.</p>
</dd>
<dt id="term-finite">finite<a class="headerlink" href="#term-finite" title="Permalink to this term">¶</a></dt><dt id="term-infinite">infinite<a class="headerlink" href="#term-infinite" title="Permalink to this term">¶</a></dt><dd><p>object absolute value is bounded (arbitrarily large).
See <a class="reference internal" href="#r98" id="id9"><span>[R98]</span></a>, <a class="reference internal" href="#r99" id="id10"><span>[R99]</span></a>, <a class="reference internal" href="#r100" id="id11"><span>[R100]</span></a>.</p>
</dd>
<dt id="term-negative">negative<a class="headerlink" href="#term-negative" title="Permalink to this term">¶</a></dt><dt id="term-nonnegative">nonnegative<a class="headerlink" href="#term-nonnegative" title="Permalink to this term">¶</a></dt><dd><p>object can have only negative (nonnegative)
values <a class="reference internal" href="#r92" id="id12"><span>[R92]</span></a>.</p>
</dd>
<dt id="term-positive">positive<a class="headerlink" href="#term-positive" title="Permalink to this term">¶</a></dt><dt id="term-nonpositive">nonpositive<a class="headerlink" href="#term-nonpositive" title="Permalink to this term">¶</a></dt><dd><p>object can have only positive (only
nonpositive) values.</p>
</dd>
<dt id="term-hermitian">hermitian<a class="headerlink" href="#term-hermitian" title="Permalink to this term">¶</a></dt><dt id="term-antihermitian">antihermitian<a class="headerlink" href="#term-antihermitian" title="Permalink to this term">¶</a></dt><dd><p>object belongs to the field of hermitian
(antihermitian) operators.</p>
</dd>
</dl>
<section id="examples">
<h3>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">);</span> <span class="n">x</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_complex</span>
<span class="go">True</span>
</pre></div>
</div>
</section>
<section id="see-also">
<h3>See Also<a class="headerlink" href="#see-also" title="Permalink to this headline">¶</a></h3>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.ImaginaryUnit" title="sympy.core.numbers.ImaginaryUnit"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.numbers.ImaginaryUnit</span></code></a>
<a class="reference internal" href="#sympy.core.numbers.Zero" title="sympy.core.numbers.Zero"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.numbers.Zero</span></code></a>
<a class="reference internal" href="#sympy.core.numbers.One" title="sympy.core.numbers.One"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.numbers.One</span></code></a></p>
</div>
</section>
<section id="notes">
<h3>Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h3>
<p>The fully-resolved assumptions for any SymPy expression
can be obtained as follows:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.assumptions</span> <span class="kn">import</span> <span class="n">assumptions</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span><span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">assumptions</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">I</span><span class="p">)</span>
<span class="go">{&#39;commutative&#39;: True, &#39;complex&#39;: True, &#39;composite&#39;: False, &#39;even&#39;:</span>
<span class="go">False, &#39;extended_negative&#39;: False, &#39;extended_nonnegative&#39;: False,</span>
<span class="go">&#39;extended_nonpositive&#39;: False, &#39;extended_nonzero&#39;: False,</span>
<span class="go">&#39;extended_positive&#39;: False, &#39;extended_real&#39;: False, &#39;finite&#39;: True,</span>
<span class="go">&#39;imaginary&#39;: False, &#39;infinite&#39;: False, &#39;integer&#39;: False, &#39;irrational&#39;:</span>
<span class="go">False, &#39;negative&#39;: False, &#39;noninteger&#39;: False, &#39;nonnegative&#39;: False,</span>
<span class="go">&#39;nonpositive&#39;: False, &#39;nonzero&#39;: False, &#39;odd&#39;: False, &#39;positive&#39;:</span>
<span class="go">False, &#39;prime&#39;: False, &#39;rational&#39;: False, &#39;real&#39;: False, &#39;zero&#39;:</span>
<span class="go">False}</span>
</pre></div>
</div>
</section>
<section id="developers-notes">
<h3>Developers Notes<a class="headerlink" href="#developers-notes" title="Permalink to this headline">¶</a></h3>
<p>The current (and possibly incomplete) values are stored
in the <code class="docutils literal notranslate"><span class="pre">obj._assumptions</span> <span class="pre">dictionary</span></code>; queries to getter methods
(with property decorators) or attributes of objects/classes
will return values and update the dictionary.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">_assumptions</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">is_finite</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">_assumptions</span>
<span class="go">{&#39;finite&#39;: True, &#39;infinite&#39;: False}</span>
</pre></div>
</div>
<p>For a Symbol, there are two locations for assumptions that may
be of interest. The <code class="docutils literal notranslate"><span class="pre">assumptions0</span></code> attribute gives the full set of
assumptions derived from a given set of initial assumptions. The
latter assumptions are stored as <code class="docutils literal notranslate"><span class="pre">Symbol._assumptions.generator</span></code></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">prime</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">even</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">_assumptions</span><span class="o">.</span><span class="n">generator</span>
<span class="go">{&#39;even&#39;: True, &#39;prime&#39;: True}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">generator</span></code> is not necessarily canonical nor is it filtered
in any way: it records the assumptions used to instantiate a Symbol
and (for storage purposes) represents a more compact representation
of the assumptions needed to recreate the full set in
<span class="math notranslate nohighlight">\(Symbol.assumptions0\)</span>.</p>
</section>
<section id="references">
<h3>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h3>
<dl class="citation">
<dt class="label" id="r92"><span class="brackets"><a class="fn-backref" href="#id12">R92</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Negative_number">https://en.wikipedia.org/wiki/Negative_number</a></p>
</dd>
<dt class="label" id="r93"><span class="brackets"><a class="fn-backref" href="#id3">R93</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Parity_(mathematics)">https://en.wikipedia.org/wiki/Parity_%28mathematics%29</a></p>
</dd>
<dt class="label" id="r94"><span class="brackets"><a class="fn-backref" href="#id2">R94</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Imaginary_number">https://en.wikipedia.org/wiki/Imaginary_number</a></p>
</dd>
<dt class="label" id="r95"><span class="brackets"><a class="fn-backref" href="#id5">R95</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Composite_number">https://en.wikipedia.org/wiki/Composite_number</a></p>
</dd>
<dt class="label" id="r96"><span class="brackets"><a class="fn-backref" href="#id8">R96</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Irrational_number">https://en.wikipedia.org/wiki/Irrational_number</a></p>
</dd>
<dt class="label" id="r97"><span class="brackets"><a class="fn-backref" href="#id4">R97</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Prime_number">https://en.wikipedia.org/wiki/Prime_number</a></p>
</dd>
<dt class="label" id="r98"><span class="brackets"><a class="fn-backref" href="#id9">R98</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Finite">https://en.wikipedia.org/wiki/Finite</a></p>
</dd>
<dt class="label" id="r99"><span class="brackets"><a class="fn-backref" href="#id10">R99</a></span></dt>
<dd><p><a class="reference external" href="https://docs.python.org/3/library/math.html#math.isfinite">https://docs.python.org/3/library/math.html#math.isfinite</a></p>
</dd>
<dt class="label" id="r100"><span class="brackets"><a class="fn-backref" href="#id11">R100</a></span></dt>
<dd><p><a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.isfinite.html">http://docs.scipy.org/doc/numpy/reference/generated/numpy.isfinite.html</a></p>
</dd>
</dl>
<dl class="footnote brackets">
<dt class="label" id="id13"><span class="brackets"><a class="fn-backref" href="#id7">10</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Transcendental_number">https://en.wikipedia.org/wiki/Transcendental_number</a></p>
</dd>
<dt class="label" id="id14"><span class="brackets"><a class="fn-backref" href="#id6">11</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Algebraic_number">https://en.wikipedia.org/wiki/Algebraic_number</a></p>
</dd>
</dl>
</section>
</section>
<section id="module-sympy.core.cache">
<span id="cache"></span><h2>cache<a class="headerlink" href="#module-sympy.core.cache" title="Permalink to this headline">¶</a></h2>
<section id="cacheit">
<h3>cacheit<a class="headerlink" href="#cacheit" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.cache.__cacheit">
<span class="sig-prename descclassname"><span class="pre">sympy.core.cache.</span></span><span class="sig-name descname"><span class="pre">__cacheit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">maxsize</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/cache.py#L43-L85"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.cache.__cacheit" title="Permalink to this definition">¶</a></dt>
<dd><p>caching decorator.</p>
<p>important: the result of cached function must be <em>immutable</em></p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.cache</span> <span class="kn">import</span> <span class="n">cacheit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nd">@cacheit</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
<span class="gp">... </span>   <span class="k">return</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@cacheit</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span> <span class="c1"># noqa: F811</span>
<span class="gp">... </span>   <span class="k">return</span> <span class="p">[</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">]</span> <span class="c1"># &lt;-- WRONG, returns mutable object</span>
</pre></div>
</div>
<p>to force cacheit to check returned results mutability and consistency,
set environment variable SYMPY_USE_CACHE to ‘debug’</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.basic">
<span id="basic"></span><h2>basic<a class="headerlink" href="#module-sympy.core.basic" title="Permalink to this headline">¶</a></h2>
<section id="id15">
<h3>Basic<a class="headerlink" href="#id15" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.basic.Basic">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.basic.</span></span><span class="sig-name descname"><span class="pre">Basic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L29-L1871"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for all SymPy objects.</p>
<p class="rubric">Notes And Conventions</p>
<ol class="arabic simple">
<li><p>Always use <code class="docutils literal notranslate"><span class="pre">.args</span></code>, when accessing parameters of some instance:</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cot</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">args</span>
<span class="go">(x,)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args</span>
<span class="go">(x, y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">y</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Never use internal methods or variables (the ones prefixed with <code class="docutils literal notranslate"><span class="pre">_</span></code>):</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">_args</span>    <span class="c1"># do not use this, use cot(x).args instead</span>
<span class="go">(x,)</span>
</pre></div>
</div>
<ol class="arabic" start="3">
<li><p>By “SymPy object” we mean something that can be returned by
<code class="docutils literal notranslate"><span class="pre">sympify</span></code>.  But not all objects one encounters using SymPy are
subclasses of Basic.  For example, mutable objects are not:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Basic</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">sympify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span><span class="o">.</span><span class="n">as_mutable</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">Basic</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">sympify</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">Basic</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</li>
</ol>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.args">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">args</span></span><a class="headerlink" href="#sympy.core.basic.Basic.args" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a tuple of arguments of ‘self’.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cot</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">args</span>
<span class="go">(x,)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args</span>
<span class="go">(x, y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">y</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Never use self._args, always use self.args.
Only use _args in __new__ when creating a new function.
Don’t override .args() from Basic (so that it’s easy to
change the interface in the future if needed).</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L754-L763"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>A stub to allow Basic args (like Tuple) to be skipped when computing
the content and primitive components of an expression.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.expr.Expr.as_content_primitive" title="sympy.core.expr.Expr.as_content_primitive"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.expr.Expr.as_content_primitive</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.as_dummy">
<span class="sig-name descname"><span class="pre">as_dummy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L518-L562"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.as_dummy" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the expression with any objects having structurally
bound symbols replaced with unique, canonical symbols within
the object in which they appear and having only the default
assumption for commutativity being True. When applied to a
symbol a new symbol having only the same commutativity will be
returned.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integral</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">as_dummy</span><span class="p">()</span>
<span class="go">Integral(_0, (_0, x))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">is_real</span> <span class="ow">is</span> <span class="kc">None</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">as_dummy</span><span class="p">()</span>
<span class="go">_r</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Any object that has structurally bound variables should have
a property, <span class="math notranslate nohighlight">\(bound_symbols\)</span> that returns those symbols
appearing in the object.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.assumptions0">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">assumptions0</span></span><a class="headerlink" href="#sympy.core.basic.Basic.assumptions0" title="Permalink to this definition">¶</a></dt>
<dd><p>Return object <span class="math notranslate nohighlight">\(type\)</span> assumptions.</p>
<p>For example:</p>
<blockquote>
<div><p>Symbol(‘x’, real=True)
Symbol(‘x’, integer=True)</p>
</div></blockquote>
<p>are different objects. In other words, besides Python type (Symbol in
this case), the initial assumptions are also forming their typeinfo.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">assumptions0</span>
<span class="go">{&#39;commutative&#39;: True}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">assumptions0</span>
<span class="go">{&#39;commutative&#39;: True, &#39;complex&#39;: True, &#39;extended_negative&#39;: False,</span>
<span class="go"> &#39;extended_nonnegative&#39;: True, &#39;extended_nonpositive&#39;: False,</span>
<span class="go"> &#39;extended_nonzero&#39;: True, &#39;extended_positive&#39;: True, &#39;extended_real&#39;:</span>
<span class="go"> True, &#39;finite&#39;: True, &#39;hermitian&#39;: True, &#39;imaginary&#39;: False,</span>
<span class="go"> &#39;infinite&#39;: False, &#39;negative&#39;: False, &#39;nonnegative&#39;: True,</span>
<span class="go"> &#39;nonpositive&#39;: False, &#39;nonzero&#39;: True, &#39;positive&#39;: True, &#39;real&#39;:</span>
<span class="go"> True, &#39;zero&#39;: False}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.atoms">
<span class="sig-name descname"><span class="pre">atoms</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">types</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L416-L493"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.atoms" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the atoms that form the current object.</p>
<p>By default, only objects that are truly atomic and can’t
be divided into smaller pieces are returned: symbols, numbers,
and number symbols like I and pi. It is possible to request
atoms of any type, however, as demonstrated below.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">()</span>
<span class="go">{1, 2, I, pi, x, y}</span>
</pre></div>
</div>
<p>If one or more types are given, the results will contain only
those types of atoms.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Number</span><span class="p">,</span> <span class="n">NumberSymbol</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Symbol</span><span class="p">)</span>
<span class="go">{x, y}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Number</span><span class="p">)</span>
<span class="go">{1, 2}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Number</span><span class="p">,</span> <span class="n">NumberSymbol</span><span class="p">)</span>
<span class="go">{1, 2, pi}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Number</span><span class="p">,</span> <span class="n">NumberSymbol</span><span class="p">,</span> <span class="n">I</span><span class="p">)</span>
<span class="go">{1, 2, I, pi}</span>
</pre></div>
</div>
<p>Note that I (imaginary unit) and zoo (complex infinity) are special
types of number symbols and are not part of the NumberSymbol class.</p>
<p>The type can be given implicitly, too:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="c1"># x is a Symbol</span>
<span class="go">{x, y}</span>
</pre></div>
</div>
<p>Be careful to check your assumptions when using the implicit option
since <code class="docutils literal notranslate"><span class="pre">S(1).is_Integer</span> <span class="pre">=</span> <span class="pre">True</span></code> but <code class="docutils literal notranslate"><span class="pre">type(S(1))</span></code> is <code class="docutils literal notranslate"><span class="pre">One</span></code>, a special type
of sympy atom, while <code class="docutils literal notranslate"><span class="pre">type(S(2))</span></code> is type <code class="docutils literal notranslate"><span class="pre">Integer</span></code> and will find all
integers in an expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="go">{1}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="go">{1, 2}</span>
</pre></div>
</div>
<p>Finally, arguments to atoms() can select more than atomic atoms: any
sympy type (loaded in core/__init__.py) can be listed as an argument
and those types of “atoms” as found in scanning the arguments of the
expression recursively:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">Mul</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">AppliedUndef</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Function</span><span class="p">)</span>
<span class="go">{f(x), sin(y + I*pi)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">AppliedUndef</span><span class="p">)</span>
<span class="go">{f(x)}</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Mul</span><span class="p">)</span>
<span class="go">{I*pi, 2*sin(y + I*pi)}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.canonical_variables">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">canonical_variables</span></span><a class="headerlink" href="#sympy.core.basic.Basic.canonical_variables" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary mapping any variable defined in
<code class="docutils literal notranslate"><span class="pre">self.bound_symbols</span></code> to Symbols that do not clash
with any free symbols in the expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Lambda</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lambda</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">canonical_variables</span>
<span class="go">{x: _0}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.class_key">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">class_key</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L277-L280"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.class_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Nice order of classes.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.compare">
<span class="sig-name descname"><span class="pre">compare</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L186-L230"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.compare" title="Permalink to this definition">¶</a></dt>
<dd><p>Return -1, 0, 1 if the object is smaller, equal, or greater than other.</p>
<p>Not in the mathematical sense. If the object is of a different type
from the “other” then their classes are ordered according to
the sorted_classes list.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">compare</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">-1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">compare</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="o">.</span><span class="n">compare</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.count">
<span class="sig-name descname"><span class="pre">count</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">query</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1519-L1522"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.count" title="Permalink to this definition">¶</a></dt>
<dd><p>Count the number of matching subexpressions.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.count_ops">
<span class="sig-name descname"><span class="pre">count_ops</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">visual</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1642-L1645"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.count_ops" title="Permalink to this definition">¶</a></dt>
<dd><p>wrapper for count_ops that returns the operation count.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.doit">
<span class="sig-name descname"><span class="pre">doit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1647-L1671"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.doit" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate objects that are not evaluated by default like limits,
integrals, sums and products. All objects of this kind will be
evaluated recursively, unless some species were excluded via ‘hints’
or unless the ‘deep’ hint was set to ‘False’.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">2*Integral(x, x)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">x**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">(</span><span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">2*Integral(x, x)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.dummy_eq">
<span class="sig-name descname"><span class="pre">dummy_eq</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbol</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L370-L414"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.dummy_eq" title="Permalink to this definition">¶</a></dt>
<dd><p>Compare two expressions and handle dummy symbols.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Dummy</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">u</span> <span class="o">=</span> <span class="n">Dummy</span><span class="p">(</span><span class="s1">&#39;u&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">dummy_eq</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">dummy_eq</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">dummy_eq</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.find">
<span class="sig-name descname"><span class="pre">find</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">query</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">group</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1501-L1517"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.find" title="Permalink to this definition">¶</a></dt>
<dd><p>Find all subexpressions matching a query.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.free_symbols">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">free_symbols</span></span><a class="headerlink" href="#sympy.core.basic.Basic.free_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Return from the atoms of self those which are free symbols.</p>
<p>For most expressions, all symbols are free symbols. For some classes
this is not true. e.g. Integrals use Symbols for the dummy variables
which are bound variables, so Integral has a method to return all
symbols except those. Derivative keeps track of symbols with respect
to which it will perform a derivative; those are
bound variables, too, so it has its own free_symbols method.</p>
<p>Any other method that uses bound variables should implement a
free_symbols method.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.fromiter">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">fromiter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L259-L275"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.fromiter" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new object from an iterable.</p>
<p>This is a convenience function that allows one to create objects from
any iterable, without having to convert to a list or tuple first.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Tuple</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Tuple</span><span class="o">.</span><span class="n">fromiter</span><span class="p">(</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
<span class="go">(0, 1, 2, 3, 4)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.func">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">func</span></span><a class="headerlink" href="#sympy.core.basic.Basic.func" title="Permalink to this definition">¶</a></dt>
<dd><p>The top-level function in an expression.</p>
<p>The following should hold for all objects:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;</span> <span class="n">x</span> <span class="o">==</span> <span class="n">x</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">func</span>
<span class="go">&lt;class &#39;sympy.core.mul.Mul&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">args</span>
<span class="go">(2, x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">a</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
<span class="go">2*x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">==</span> <span class="n">a</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">a</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.has">
<span class="sig-name descname"><span class="pre">has</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">patterns</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1168-L1215"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.has" title="Permalink to this definition">¶</a></dt>
<dd><p>Test whether any subexpression matches any of the patterns.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Note <code class="docutils literal notranslate"><span class="pre">has</span></code> is a structural algorithm with no knowledge of
mathematics. Consider the following half-open interval:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.sets</span> <span class="kn">import</span> <span class="n">Interval</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Interval</span><span class="o">.</span><span class="n">Lopen</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">);</span> <span class="n">i</span>
<span class="go">Interval.Lopen(0, 5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">args</span>
<span class="go">(0, 5, True, False)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>  <span class="c1"># there is no &quot;4&quot; in the arguments</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>  <span class="c1"># there *is* a &quot;0&quot; in the arguments</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Instead, use <code class="docutils literal notranslate"><span class="pre">contains</span></code> to determine whether a number is in the
interval or not:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">expr.has(*patterns)</span></code> is exactly equivalent to
<code class="docutils literal notranslate"><span class="pre">any(expr.has(p)</span> <span class="pre">for</span> <span class="pre">p</span> <span class="pre">in</span> <span class="pre">patterns)</span></code>. In particular, <code class="docutils literal notranslate"><span class="pre">False</span></code> is
returned when the list of patterns is empty.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">has</span><span class="p">()</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.is_comparable">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_comparable</span></span><a class="headerlink" href="#sympy.core.basic.Basic.is_comparable" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if self can be computed to a real number
(or already is a real number) with precision, else False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp_polar</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">exp_polar</span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">is_comparable</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">exp_polar</span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">is_comparable</span>
<span class="go">False</span>
</pre></div>
</div>
<p>A False result does not mean that <span class="math notranslate nohighlight">\(self\)</span> cannot be rewritten
into a form that would be comparable. For example, the
difference computed below is zero but without simplification
it does not evaluate to a zero with precision:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="mi">2</span><span class="o">**</span><span class="n">pi</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span><span class="o">**</span><span class="n">pi</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dif</span> <span class="o">=</span> <span class="n">e</span> <span class="o">-</span> <span class="n">e</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dif</span><span class="o">.</span><span class="n">is_comparable</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dif</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">_prec</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.match">
<span class="sig-name descname"><span class="pre">match</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pattern</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">old</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1560-L1640"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.match" title="Permalink to this definition">¶</a></dt>
<dd><p>Pattern matching.</p>
<p>Wild symbols match all.</p>
<p>Return <code class="docutils literal notranslate"><span class="pre">None</span></code> when expression (self) does not match
with pattern. Otherwise return a dictionary such that:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pattern</span><span class="o">.</span><span class="n">xreplace</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">pattern</span><span class="p">))</span> <span class="o">==</span> <span class="bp">self</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Wild</span><span class="p">,</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s2">&quot;p&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s2">&quot;q&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s2">&quot;r&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span><span class="o">**</span><span class="n">p</span><span class="p">)</span>
<span class="go">{p_: x + y}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span><span class="o">**</span><span class="n">q</span><span class="p">)</span>
<span class="go">{p_: x + y, q_: x + y}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="o">**</span><span class="n">r</span><span class="p">)</span>
<span class="go">{p_: 4, q_: x, r_: 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="o">**</span><span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="o">**</span><span class="n">r</span><span class="p">))</span>
<span class="go">4*x**2</span>
</pre></div>
</div>
<p>Structurally bound symbols are ignored during matching:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">Sum</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">p</span><span class="p">)))</span>
<span class="go">{p_: 2}</span>
</pre></div>
</div>
<p>But they can be identified if desired:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">Sum</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">p</span><span class="p">)))</span>
<span class="go">{p_: 2, q_: x}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">old</span></code> flag will give the old-style pattern matching where
expressions and patterns are essentially solved to give the
match. Both of the following give None unless <code class="docutils literal notranslate"><span class="pre">old=True</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span> <span class="o">-</span> <span class="n">x</span><span class="p">,</span> <span class="n">old</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">{p_: 2*x - 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">x</span><span class="p">,</span> <span class="n">old</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">{p_: 2/x**2}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.matches">
<span class="sig-name descname"><span class="pre">matches</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">repl_dict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">old</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1524-L1558"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.matches" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper method for match() that looks for a match between Wild symbols
in self and expressions in expr.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Wild</span><span class="p">,</span> <span class="n">Basic</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Basic</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">Basic</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">))</span> <span class="ow">is</span> <span class="kc">None</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Basic</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">Basic</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">,</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">))</span>
<span class="go">{x_: b + c}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.rcall">
<span class="sig-name descname"><span class="pre">rcall</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L595-L610"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.rcall" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply on the argument recursively through the expression tree.</p>
<p>This method is used to simulate a common abuse of notation for
operators. For instance in SymPy the the following will not work:</p>
<p><code class="docutils literal notranslate"><span class="pre">(x+Lambda(y,</span> <span class="pre">2*y))(z)</span> <span class="pre">==</span> <span class="pre">x+2*z</span></code>,</p>
<p>however you can use</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Lambda</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">Lambda</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">rcall</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
<span class="go">x + 2*z</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.refine">
<span class="sig-name descname"><span class="pre">refine</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">assumption</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1678-L1681"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.refine" title="Permalink to this definition">¶</a></dt>
<dd><p>See the refine function in sympy.assumptions</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.replace">
<span class="sig-name descname"><span class="pre">replace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">query</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">map</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">simultaneous</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exact</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1241-L1499"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.replace" title="Permalink to this definition">¶</a></dt>
<dd><p>Replace matching subexpressions of <code class="docutils literal notranslate"><span class="pre">self</span></code> with <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">map</span> <span class="pre">=</span> <span class="pre">True</span></code> then also return the mapping {old: new} where <code class="docutils literal notranslate"><span class="pre">old</span></code>
was a sub-expression found with query and <code class="docutils literal notranslate"><span class="pre">new</span></code> is the replacement
value for it. If the expression itself doesn’t match the query, then
the returned value will be <code class="docutils literal notranslate"><span class="pre">self.xreplace(map)</span></code> otherwise it should
be <code class="docutils literal notranslate"><span class="pre">self.subs(ordered(map.items()))</span></code>.</p>
<p>Traverses an expression tree and performs replacement of matching
subexpressions from the bottom to the top of the tree. The default
approach is to do the replacement in a simultaneous fashion so
changes made are targeted only once. If this is not desired or causes
problems, <code class="docutils literal notranslate"><span class="pre">simultaneous</span></code> can be set to False.</p>
<p>In addition, if an expression containing more than one Wild symbol
is being used to match subexpressions and the <code class="docutils literal notranslate"><span class="pre">exact</span></code> flag is None
it will be set to True so the match will only succeed if all non-zero
values are received for each Wild that appears in the match pattern.
Setting this to False accepts a match of 0; while setting it True
accepts all matches that have a 0 in them. See example below for
cautions.</p>
<p>The list of possible combinations of queries and replacement values
is listed below:</p>
<p class="rubric">Examples</p>
<p>Initial setup</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">log</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">tan</span><span class="p">,</span> <span class="n">Wild</span><span class="p">,</span> <span class="n">Mul</span><span class="p">,</span> <span class="n">Add</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">log</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="o">+</span> <span class="n">tan</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
<dl>
<dt>1.1. type -&gt; type</dt><dd><p>obj.replace(type, newtype)</p>
<p>When object of type <code class="docutils literal notranslate"><span class="pre">type</span></code> is found, replace it with the
result of passing its argument(s) to <code class="docutils literal notranslate"><span class="pre">newtype</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">)</span>
<span class="go">log(cos(x)) + tan(cos(x**2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="nb">map</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(cos(x), {sin(x): cos(x)})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">Mul</span><span class="p">,</span> <span class="n">Add</span><span class="p">)</span>
<span class="go">x + y</span>
</pre></div>
</div>
</dd>
<dt>1.2. type -&gt; func</dt><dd><p>obj.replace(type, func)</p>
<p>When object of type <code class="docutils literal notranslate"><span class="pre">type</span></code> is found, apply <code class="docutils literal notranslate"><span class="pre">func</span></code> to its
argument(s). <code class="docutils literal notranslate"><span class="pre">func</span></code> must be written to handle the number
of arguments of <code class="docutils literal notranslate"><span class="pre">type</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">arg</span><span class="p">:</span> <span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">arg</span><span class="p">))</span>
<span class="go">log(sin(2*x)) + tan(sin(2*x**2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">Mul</span><span class="p">,</span> <span class="k">lambda</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">Mul</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)))</span>
<span class="go">sin(2*x*y)</span>
</pre></div>
</div>
</dd>
<dt>2.1. pattern -&gt; expr</dt><dd><p>obj.replace(pattern(wild), expr(wild))</p>
<p>Replace subexpressions matching <code class="docutils literal notranslate"><span class="pre">pattern</span></code> with the expression
written in terms of the Wild symbols in <code class="docutils literal notranslate"><span class="pre">pattern</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">Wild</span><span class="p">,</span> <span class="s1">&#39;ab&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">tan</span><span class="p">(</span><span class="n">a</span><span class="p">))</span>
<span class="go">log(tan(x)) + tan(tan(x**2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">tan</span><span class="p">(</span><span class="n">a</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="go">log(tan(x/2)) + tan(tan(x**2/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">a</span><span class="p">)</span>
<span class="go">log(x) + tan(x**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="go">y</span>
</pre></div>
</div>
<p>Matching is exact by default when more than one Wild symbol
is used: matching fails unless the match gives non-zero
values for all Wild symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">b</span><span class="p">,</span> <span class="n">b</span> <span class="o">-</span> <span class="n">a</span><span class="p">)</span>
<span class="go">y - 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">b</span><span class="p">,</span> <span class="n">b</span> <span class="o">-</span> <span class="n">a</span><span class="p">)</span>
<span class="go">2*x</span>
</pre></div>
</div>
<p>When set to False, the results may be non-intuitive:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">b</span><span class="p">,</span> <span class="n">b</span> <span class="o">-</span> <span class="n">a</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">2/x</span>
</pre></div>
</div>
</dd>
<dt>2.2. pattern -&gt; func</dt><dd><p>obj.replace(pattern(wild), lambda wild: expr(wild))</p>
<p>All behavior is the same as in 2.1 but now a function in terms of
pattern variables is used rather than an expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">a</span><span class="p">))</span>
<span class="go">log(sin(2*x)) + tan(sin(2*x**2))</span>
</pre></div>
</div>
</dd>
<dt>3.1. func -&gt; func</dt><dd><p>obj.replace(filter, func)</p>
<p>Replace subexpression <code class="docutils literal notranslate"><span class="pre">e</span></code> with <code class="docutils literal notranslate"><span class="pre">func(e)</span></code> if <code class="docutils literal notranslate"><span class="pre">filter(e)</span></code>
is True.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="k">lambda</span> <span class="n">expr</span><span class="p">:</span> <span class="n">expr</span><span class="o">.</span><span class="n">is_Number</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">expr</span><span class="p">:</span> <span class="n">expr</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">4*sin(x**9)</span>
</pre></div>
</div>
</dd>
</dl>
<p>The expression itself is also targeted by the query but is done in
such a fashion that changes are not made twice.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Mul</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
<span class="go">2*x*(2*x*y + 1)</span>
</pre></div>
</div>
<p>When matching a single symbol, <span class="math notranslate nohighlight">\(exact\)</span> will default to True, but
this may or may not be the behavior that is desired:</p>
<p>Here, we want <span class="math notranslate nohighlight">\(exact=False\)</span>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">f</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">f</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="o">*</span><span class="n">q</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">f(1) + f(2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="o">*</span><span class="n">q</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">f(0) + f(2)</span>
</pre></div>
</div>
<p>But here, the nature of matching makes selecting
the right setting tricky:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">x</span><span class="o">**-</span><span class="n">a</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">x</span><span class="o">**-</span><span class="n">a</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**(-x - y + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">x</span><span class="o">**-</span><span class="n">a</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">a</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">x</span><span class="o">**-</span><span class="n">a</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**(1 - y)</span>
</pre></div>
</div>
<p>It is probably better to use a different form of the query
that describes the target expression more precisely:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span>
<span class="gp">... </span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Pow</span> <span class="ow">and</span> <span class="n">x</span><span class="o">.</span><span class="n">exp</span><span class="o">.</span><span class="n">is_Add</span> <span class="ow">and</span> <span class="n">x</span><span class="o">.</span><span class="n">exp</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span>
<span class="gp">... </span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">base</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">exp</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)))</span>
<span class="gp">...</span>
<span class="go">x**(1 - y) + 1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.basic.Basic.subs" title="sympy.core.basic.Basic.subs"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subs</span></code></a></dt><dd><p>substitution of subexpressions as defined by the objects themselves.</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.basic.Basic.xreplace" title="sympy.core.basic.Basic.xreplace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">xreplace</span></code></a></dt><dd><p>exact node replacement in expr tree; also capable of using matching rules</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.rewrite">
<span class="sig-name descname"><span class="pre">rewrite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1702-L1803"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.rewrite" title="Permalink to this definition">¶</a></dt>
<dd><p>Rewrite <em>self</em> using a defined rule.</p>
<p>Rewriting transforms an expression to another, which is mathematically
equivalent but structurally different. For example you can rewrite
trigonometric functions as complex exponentials or combinatorial
functions as gamma function.</p>
<p>This method takes a <em>pattern</em> and a <em>rule</em> as positional arguments.
<em>pattern</em> is optional parameter which defines the types of expressions
that will be transformed. If it is not passed, all possible expressions
will be rewritten. <em>rule</em> defines how the expression will be rewritten.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>args</strong> : <em>rule</em>, or <em>pattern</em> and <em>rule</em>.</p>
<blockquote>
<div><ul class="simple">
<li><p><em>pattern</em> is a type or an iterable of types.</p></li>
<li><p><em>rule</em> can be any object.</p></li>
</ul>
</div></blockquote>
<p><strong>deep</strong> : bool, optional.</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, subexpressions are recursively transformed. Default is
<code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>If <em>pattern</em> is unspecified, all possible expressions are transformed.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">exp</span><span class="p">)</span>
<span class="go">exp(I*x)</span>
</pre></div>
</div>
<p>Pattern can be a type or an iterable of types.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">sin</span><span class="p">,</span> <span class="n">exp</span><span class="p">)</span>
<span class="go">exp(I*x)/2 + cos(x) - exp(-I*x)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">([</span><span class="n">cos</span><span class="p">,],</span> <span class="n">exp</span><span class="p">)</span>
<span class="go">exp(I*x)/2 + I*sin(x) + exp(-I*x)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">([</span><span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">],</span> <span class="n">exp</span><span class="p">)</span>
<span class="go">exp(I*x)</span>
</pre></div>
</div>
<p>Rewriting behavior can be implemented by defining <code class="docutils literal notranslate"><span class="pre">_eval_rewrite()</span></code>
method.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Expr</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MySin</span><span class="p">(</span><span class="n">Expr</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_eval_rewrite</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rule</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">hints</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">x</span><span class="p">,</span> <span class="o">=</span> <span class="n">args</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">rule</span> <span class="o">==</span> <span class="n">cos</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">return</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">rule</span> <span class="o">==</span> <span class="n">sqrt</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">return</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MySin</span><span class="p">(</span><span class="n">MySin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">cos</span><span class="p">)</span>
<span class="go">cos(-cos(-x + pi/2) + pi/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MySin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">sqrt</span><span class="p">)</span>
<span class="go">sqrt(1 - cos(x)**2)</span>
</pre></div>
</div>
<p>Defining <code class="docutils literal notranslate"><span class="pre">_eval_rewrite_as_[...]()</span></code> method is supported for backwards
compatibility reason. This may be removed in the future and using it is
discouraged.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MySin</span><span class="p">(</span><span class="n">Expr</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_eval_rewrite_as_cos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">hints</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">x</span><span class="p">,</span> <span class="o">=</span> <span class="n">args</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MySin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">cos</span><span class="p">)</span>
<span class="go">cos(-x + pi/2)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.simplify">
<span class="sig-name descname"><span class="pre">simplify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1673-L1676"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.simplify" title="Permalink to this definition">¶</a></dt>
<dd><p>See the simplify function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.sort_key">
<span class="sig-name descname"><span class="pre">sort_key</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L282-L311"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.sort_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a sort key.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">I</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">([</span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="o">-</span><span class="n">I</span><span class="p">],</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">sort_key</span><span class="p">())</span>
<span class="go">[1/2, -I, I]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="s2">&quot;[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]&quot;</span><span class="p">)</span>
<span class="go">[x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">sort_key</span><span class="p">())</span>
<span class="go">[x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.subs">
<span class="sig-name descname"><span class="pre">subs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L765-L956"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.subs" title="Permalink to this definition">¶</a></dt>
<dd><p>Substitutes old for new in an expression after sympifying args.</p>
<dl class="simple">
<dt><span class="math notranslate nohighlight">\(args\)</span> is either:</dt><dd><ul class="simple">
<li><p>two arguments, e.g. foo.subs(old, new)</p></li>
<li><dl class="simple">
<dt>one iterable argument, e.g. foo.subs(iterable). The iterable may be</dt><dd><dl class="simple">
<dt>o an iterable container with (old, new) pairs. In this case the</dt><dd><p>replacements are processed in the order given with successive
patterns possibly affecting replacements already made.</p>
</dd>
<dt>o a dict or set whose key/value items correspond to old/new pairs.</dt><dd><p>In this case the old/new pairs will be sorted by op count and in
case of a tie, by number of args and the default_sort_key. The
resulting sorted list is then processed as an iterable container
(see previous).</p>
</dd>
</dl>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
<p>If the keyword <code class="docutils literal notranslate"><span class="pre">simultaneous</span></code> is True, the subexpressions will not be
evaluated until all the substitutions have been made.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">limit</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pi</span><span class="p">)</span>
<span class="go">pi*y + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span><span class="n">pi</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span><span class="mi">2</span><span class="p">})</span>
<span class="go">1 + 2*pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">([(</span><span class="n">x</span><span class="p">,</span> <span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">)])</span>
<span class="go">1 + 2*pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">reps</span> <span class="o">=</span> <span class="p">[(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">reps</span><span class="p">)</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">reps</span><span class="p">))</span>
<span class="go">x**2 + 2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">y**2 + y</span>
</pre></div>
</div>
<p>To replace only the x**2 but not the x**4, use xreplace:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">:</span> <span class="n">y</span><span class="p">})</span>
<span class="go">x**4 + y</span>
</pre></div>
</div>
<p>To delay evaluation until all substitutions have been made,
set the keyword <code class="docutils literal notranslate"><span class="pre">simultaneous</span></code> to True:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">([(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">([(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)],</span> <span class="n">simultaneous</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">nan</span>
</pre></div>
</div>
<p>This has the added feature of not allowing subsequent substitutions
to affect those already made:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">})</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">},</span> <span class="n">simultaneous</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">y/(x + y)</span>
</pre></div>
</div>
<p>In order to obtain a canonical result, unordered iterables are
sorted by count_op length, number of arguments and by the
default_sort_key to break any ties. All other iterables are left
unsorted.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">e</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)),</span> <span class="n">a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">),</span> <span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">),</span> <span class="n">c</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span> <span class="o">=</span> <span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">e</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">))</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="nb">dict</span><span class="p">([</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">E</span><span class="p">]))</span>
<span class="go">a*c*sin(d*e) + b</span>
</pre></div>
</div>
<p>The resulting expression represents a literal replacement of the
old arguments with the new arguments. This may not reflect the
limiting behavior of the expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">-</span> <span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">oo</span><span class="p">})</span>
<span class="go">nan</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">-</span> <span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">oo</span>
</pre></div>
</div>
<p>If the substitution will be followed by numerical
evaluation, it is better to pass the substitution to
evalf as</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="n">subs</span><span class="o">=</span><span class="p">{</span><span class="n">x</span><span class="p">:</span> <span class="mf">3.0</span><span class="p">},</span> <span class="n">n</span><span class="o">=</span><span class="mi">21</span><span class="p">)</span>
<span class="go">0.333333333333333333333</span>
</pre></div>
</div>
<p>rather than</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="mf">3.0</span><span class="p">})</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">21</span><span class="p">)</span>
<span class="go">0.333333333333333314830</span>
</pre></div>
</div>
<p>as the former will ensure that the desired level of precision is
obtained.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.basic.Basic.replace" title="sympy.core.basic.Basic.replace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">replace</span></code></a></dt><dd><p>replacement capable of doing wildcard-like matching, parsing of match, and conditional replacements</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.basic.Basic.xreplace" title="sympy.core.basic.Basic.xreplace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">xreplace</span></code></a></dt><dd><p>exact node replacement in expr tree; also capable of using matching rules</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.evalf.EvalfMixin.evalf" title="sympy.core.evalf.EvalfMixin.evalf"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.evalf.EvalfMixin.evalf</span></code></a></dt><dd><p>calculates the given formula to a desired level of precision</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.basic.Basic.xreplace">
<span class="sig-name descname"><span class="pre">xreplace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1081-L1144"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Basic.xreplace" title="Permalink to this definition">¶</a></dt>
<dd><p>Replace occurrences of objects within the expression.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rule</strong> : dict-like</p>
<blockquote>
<div><p>Expresses a replacement rule</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>xreplace</strong> : the result of the replacement</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">exp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">pi</span><span class="p">})</span>
<span class="go">pi*y + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">pi</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>
<span class="go">1 + 2*pi</span>
</pre></div>
</div>
<p>Replacements occur only if an entire node in the expression tree is
matched:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">:</span> <span class="n">pi</span><span class="p">})</span>
<span class="go">z + pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">:</span> <span class="n">pi</span><span class="p">})</span>
<span class="go">x*y*z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">z</span><span class="p">})</span>
<span class="go">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">z</span><span class="p">})</span>
<span class="go">4*z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>
<span class="go">x + y + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:</span> <span class="n">y</span><span class="p">})</span>
<span class="go">x + exp(y) + 2</span>
</pre></div>
</div>
<p>xreplace doesn’t differentiate between free and bound symbols. In the
following, subs(x, y) would not change x since it is a bound symbol,
but xreplace does:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">y</span><span class="p">})</span>
<span class="go">Integral(y, (y, 1, 2*y))</span>
</pre></div>
</div>
<p>Trying to replace x with an expression raises an error:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">xreplace</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">})</span> 
<span class="go">ValueError: Invalid limits given: ((2*y, 1, 4*y),)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.basic.Basic.replace" title="sympy.core.basic.Basic.replace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">replace</span></code></a></dt><dd><p>replacement capable of doing wildcard-like matching, parsing of match, and conditional replacements</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.basic.Basic.subs" title="sympy.core.basic.Basic.subs"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subs</span></code></a></dt><dd><p>substitution of subexpressions as defined by the objects themselves.</p>
</dd>
</dl>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="atom">
<h3>Atom<a class="headerlink" href="#atom" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.basic.Atom">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.basic.</span></span><span class="sig-name descname"><span class="pre">Atom</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/basic.py#L1874-L1917"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.basic.Atom" title="Permalink to this definition">¶</a></dt>
<dd><p>A parent class for atomic things. An atom is an expression with no subexpressions.</p>
<p class="rubric">Examples</p>
<p>Symbol, Number, Rational, Integer, …
But not: Add, Mul, Pow, …</p>
</dd></dl>

</section>
</section>
<section id="id16">
<h2>core<a class="headerlink" href="#id16" title="Permalink to this headline">¶</a></h2>
<span class="target" id="module-sympy.core.core"></span></section>
<section id="module-sympy.core.singleton">
<span id="singleton"></span><h2>singleton<a class="headerlink" href="#module-sympy.core.singleton" title="Permalink to this headline">¶</a></h2>
<section id="s">
<h3>S<a class="headerlink" href="#s" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.singleton.SingletonRegistry">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.singleton.</span></span><span class="sig-name descname"><span class="pre">SingletonRegistry</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/singleton.py#L9-L130"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.singleton.SingletonRegistry" title="Permalink to this definition">¶</a></dt>
<dd><p>The registry for the singleton classes (accessible as <code class="docutils literal notranslate"><span class="pre">S</span></code>).</p>
<p class="rubric">Explanation</p>
<p>This class serves as two separate things.</p>
<p>The first thing it is is the <code class="docutils literal notranslate"><span class="pre">SingletonRegistry</span></code>. Several classes in
SymPy appear so often that they are singletonized, that is, using some
metaprogramming they are made so that they can only be instantiated once
(see the <a class="reference internal" href="#sympy.core.singleton.Singleton" title="sympy.core.singleton.Singleton"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.singleton.Singleton</span></code></a> class for details). For
instance, every time you create <code class="docutils literal notranslate"><span class="pre">Integer(0)</span></code>, this will return the same
instance, <a class="reference internal" href="#sympy.core.numbers.Zero" title="sympy.core.numbers.Zero"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.numbers.Zero</span></code></a>. All singleton instances are
attributes of the <code class="docutils literal notranslate"><span class="pre">S</span></code> object, so <code class="docutils literal notranslate"><span class="pre">Integer(0)</span></code> can also be accessed as
<code class="docutils literal notranslate"><span class="pre">S.Zero</span></code>.</p>
<p>Singletonization offers two advantages: it saves memory, and it allows
fast comparison. It saves memory because no matter how many times the
singletonized objects appear in expressions in memory, they all point to
the same single instance in memory. The fast comparison comes from the
fact that you can use <code class="docutils literal notranslate"><span class="pre">is</span></code> to compare exact instances in Python
(usually, you need to use <code class="docutils literal notranslate"><span class="pre">==</span></code> to compare things). <code class="docutils literal notranslate"><span class="pre">is</span></code> compares
objects by memory address, and is very fast.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Integer</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="go">True</span>
</pre></div>
</div>
<p>For the most part, the fact that certain objects are singletonized is an
implementation detail that users shouldn’t need to worry about. In SymPy
library code, <code class="docutils literal notranslate"><span class="pre">is</span></code> comparison is often used for performance purposes
The primary advantage of <code class="docutils literal notranslate"><span class="pre">S</span></code> for end users is the convenient access to
certain instances that are otherwise difficult to type, like <code class="docutils literal notranslate"><span class="pre">S.Half</span></code>
(instead of <code class="docutils literal notranslate"><span class="pre">Rational(1,</span> <span class="pre">2)</span></code>).</p>
<p>When using <code class="docutils literal notranslate"><span class="pre">is</span></code> comparison, make sure the argument is sympified. For
instance,</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="go">False</span>
</pre></div>
</div>
<p>This problem is not an issue when using <code class="docutils literal notranslate"><span class="pre">==</span></code>, which is recommended for
most use-cases:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">0</span> <span class="o">==</span> <span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The second thing <code class="docutils literal notranslate"><span class="pre">S</span></code> is is a shortcut for
<a class="reference internal" href="#sympy.core.sympify.sympify" title="sympy.core.sympify.sympify"><code class="xref py py-func docutils literal notranslate"><span class="pre">sympy.core.sympify.sympify()</span></code></a>. <a class="reference internal" href="#sympy.core.sympify.sympify" title="sympy.core.sympify.sympify"><code class="xref py py-func docutils literal notranslate"><span class="pre">sympy.core.sympify.sympify()</span></code></a> is
the function that converts Python objects such as <code class="docutils literal notranslate"><span class="pre">int(1)</span></code> into SymPy
objects such as <code class="docutils literal notranslate"><span class="pre">Integer(1)</span></code>. It also converts the string form of an
expression into a SymPy expression, like <code class="docutils literal notranslate"><span class="pre">sympify(&quot;x**2&quot;)</span></code> -&gt;
<code class="docutils literal notranslate"><span class="pre">Symbol(&quot;x&quot;)**2</span></code>. <code class="docutils literal notranslate"><span class="pre">S(1)</span></code> is the same thing as <code class="docutils literal notranslate"><span class="pre">sympify(1)</span></code>
(basically, <code class="docutils literal notranslate"><span class="pre">S.__call__</span></code> has been defined to call <code class="docutils literal notranslate"><span class="pre">sympify</span></code>).</p>
<p>This is for convenience, since <code class="docutils literal notranslate"><span class="pre">S</span></code> is a single letter. It’s mostly
useful for defining rational numbers. Consider an expression like <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span>
<span class="pre">1/2</span></code>. If you enter this directly in Python, it will evaluate the <code class="docutils literal notranslate"><span class="pre">1/2</span></code>
and give <code class="docutils literal notranslate"><span class="pre">0.5</span></code> (or just <code class="docutils literal notranslate"><span class="pre">0</span></code> in Python 2, because of integer division),
because both arguments are ints (see also
<a class="reference internal" href="../tutorial/gotchas.html#tutorial-gotchas-final-notes"><span class="std std-ref">Two Final Notes: ^ and /</span></a>). However, in SymPy, you usually want
the quotient of two integers to give an exact rational number. The way
Python’s evaluation works, at least one side of an operator needs to be a
SymPy object for the SymPy evaluation to take over. You could write this
as <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">Rational(1,</span> <span class="pre">2)</span></code>, but this is a lot more typing. A shorter
version is <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">S(1)/2</span></code>. Since <code class="docutils literal notranslate"><span class="pre">S(1)</span></code> returns <code class="docutils literal notranslate"><span class="pre">Integer(1)</span></code>, the
division will return a <code class="docutils literal notranslate"><span class="pre">Rational</span></code> type, since it will call
<code class="docutils literal notranslate"><span class="pre">Integer.__truediv__</span></code>, which knows how to return a <code class="docutils literal notranslate"><span class="pre">Rational</span></code>.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.singleton.Singleton">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.singleton.</span></span><span class="sig-name descname"><span class="pre">Singleton</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/singleton.py#L135-L178"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.singleton.Singleton" title="Permalink to this definition">¶</a></dt>
<dd><p>Metaclass for singleton classes.</p>
<p class="rubric">Explanation</p>
<p>A singleton class has only one instance which is returned every time the
class is instantiated. Additionally, this instance can be accessed through
the global registry object <code class="docutils literal notranslate"><span class="pre">S</span></code> as <code class="docutils literal notranslate"><span class="pre">S.&lt;class_name&gt;</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Basic</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.singleton</span> <span class="kn">import</span> <span class="n">Singleton</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MySingleton</span><span class="p">(</span><span class="n">Basic</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">Singleton</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">pass</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Basic</span><span class="p">()</span> <span class="ow">is</span> <span class="n">Basic</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MySingleton</span><span class="p">()</span> <span class="ow">is</span> <span class="n">MySingleton</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">MySingleton</span> <span class="ow">is</span> <span class="n">MySingleton</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Instance creation is delayed until the first time the value is accessed.
(SymPy versions before 1.0 would create the instance during class
creation time, which would be prone to import cycles.)</p>
<p>This metaclass is a subclass of ManagedProperties because that is the
metaclass of many classes that need to be Singletons (Python does not allow
subclasses to have a different metaclass than the superclass, except the
subclass may use a subclassed metaclass).</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.expr">
<span id="expr"></span><h2>expr<a class="headerlink" href="#module-sympy.core.expr" title="Permalink to this headline">¶</a></h2>
<section id="id17">
<h3>Expr<a class="headerlink" href="#id17" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.expr.Expr">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.expr.</span></span><span class="sig-name descname"><span class="pre">Expr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L19-L3899"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for algebraic expressions.</p>
<p class="rubric">Explanation</p>
<p>Everything that requires arithmetic operations to be defined
should subclass this class, instead of Basic (which should be
used only for argument storage and expression manipulation, i.e.
pattern matching, substitutions, etc).</p>
<p>If you want to override the comparisons of expressions:
Should use _eval_is_ge for inequality, or _eval_is_eq, with multiple dispatch.
_eval_is_ge return true if x &gt;= y, false if x &lt; y, and None if the two types
are not comparable or the comparison is indeterminate</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.basic.Basic</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.apart">
<span class="sig-name descname"><span class="pre">apart</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3688-L3691"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.apart" title="Permalink to this definition">¶</a></dt>
<dd><p>See the apart function in sympy.polys</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.args_cnc">
<span class="sig-name descname"><span class="pre">args_cnc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">split_1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1309-L1373"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.args_cnc" title="Permalink to this definition">¶</a></dt>
<dd><p>Return [commutative factors, non-commutative factors] of self.</p>
<p class="rubric">Explanation</p>
<p>self is treated as a Mul and the ordering of the factors is maintained.
If <code class="docutils literal notranslate"><span class="pre">cset</span></code> is True the commutative factors will be returned in a set.
If there were repeated factors (as may happen with an unevaluated Mul)
then an error will be raised unless it is explicitly suppressed by
setting <code class="docutils literal notranslate"><span class="pre">warn</span></code> to False.</p>
<p>Note: -1 is always separated from a Number unless split_1 is False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;A B&#39;</span><span class="p">,</span> <span class="n">commutative</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">()</span>
<span class="go">[[-1, 2, x, y], []]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mf">2.5</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">()</span>
<span class="go">[[-1, 2.5, x], []]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">()</span>
<span class="go">[[-1, 2, x, y], [A, B]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">(</span><span class="n">split_1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">[[-2, x, y], [A, B]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">(</span><span class="n">cset</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">[{-1, 2, x, y}, []]</span>
</pre></div>
</div>
<p>The arg is always treated as a Mul:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">A</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">()</span>
<span class="go">[[], [x - 2 + A]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">oo</span><span class="p">)</span><span class="o">.</span><span class="n">args_cnc</span><span class="p">()</span> <span class="c1"># -oo is a singleton</span>
<span class="go">[[-1, oo], []]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coeff_Add">
<span class="sig-name descname"><span class="pre">as_coeff_Add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3494-L3496"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coeff_Add" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a summation.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3490-L3492"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a product.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coeff_add">
<span class="sig-name descname"><span class="pre">as_coeff_add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">deps</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2035-L2069"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coeff_add" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (c, args) where self is written as an Add, <code class="docutils literal notranslate"><span class="pre">a</span></code>.</p>
<p>c should be a Rational added to any terms of the Add that are
independent of deps.</p>
<p>args should be a tuple of all other terms of <code class="docutils literal notranslate"><span class="pre">a</span></code>; args is empty
if self is a Number or if self is independent of deps (when given).</p>
<p>This should be used when you don’t know if self is an Add or not but
you want to treat self as an Add or if you want to process the
individual arguments of the tail of self as an Add.</p>
<ul class="simple">
<li><p>if you know self is an Add and want only the head, use self.args[0];</p></li>
<li><p>if you don’t want to process the arguments of the tail but need the
tail then use self.as_two_terms() which gives the head and tail.</p></li>
<li><p>if you want to split self into an independent and dependent parts
use <code class="docutils literal notranslate"><span class="pre">self.as_independent(*deps)</span></code></p></li>
</ul>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">()</span>
<span class="go">(3, ())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">()</span>
<span class="go">(3, (x,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(y + 3, (x,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(y + 3, ())</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coeff_exponent">
<span class="sig-name descname"><span class="pre">as_coeff_exponent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3450-L3460"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coeff_exponent" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">c*x**e</span> <span class="pre">-&gt;</span> <span class="pre">c,e</span></code> where x can be any symbolic expression.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coeff_mul">
<span class="sig-name descname"><span class="pre">as_coeff_mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">deps</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2000-L2033"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coeff_mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (c, args) where self is written as a Mul, <code class="docutils literal notranslate"><span class="pre">m</span></code>.</p>
<p>c should be a Rational multiplied by any factors of the Mul that are
independent of deps.</p>
<p>args should be a tuple of all other factors of m; args is empty
if self is a Number or if self is independent of deps (when given).</p>
<p>This should be used when you don’t know if self is a Mul or not but
you want to treat self as a Mul or if you want to process the
individual arguments of the tail of self as a Mul.</p>
<ul class="simple">
<li><p>if you know self is a Mul and want only the head, use self.args[0];</p></li>
<li><p>if you don’t want to process the arguments of the tail but need the
tail then use self.as_two_terms() which gives the head and tail;</p></li>
<li><p>if you want to split self into an independent and dependent parts
use <code class="docutils literal notranslate"><span class="pre">self.as_independent(*deps)</span></code></p></li>
</ul>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">as_coeff_mul</span><span class="p">()</span>
<span class="go">(3, ())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_mul</span><span class="p">()</span>
<span class="go">(3, (x, y))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_mul</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(3*y, (x,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_mul</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(3*y, ())</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coefficient">
<span class="sig-name descname"><span class="pre">as_coefficient</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1665-L1731"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coefficient" title="Permalink to this definition">¶</a></dt>
<dd><p>Extracts symbolic coefficient at the given expression. In
other words, this functions separates ‘self’ into the product
of ‘expr’ and ‘expr’-free coefficient. If such separation
is not possible it will return None.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">E</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="n">Poly</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">E</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">E</span><span class="p">)</span><span class="o">*</span><span class="n">E</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
</pre></div>
</div>
<p>Two terms have E in them so a sum is returned. (If one were
desiring the coefficient of the term exactly matching E then
the constant from the returned expression could be selected.
Or, for greater precision, a method of Poly can be used to
indicate the desired term from which the coefficient is
desired.)</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">E</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">E</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">x + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>  <span class="c1"># just want the exact match</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Poly</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">E</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">E</span><span class="p">);</span> <span class="n">p</span>
<span class="go">Poly(x*E + 2*E, x, E, domain=&#39;ZZ&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">coeff_monomial</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">nth</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Since the following cannot be written as a product containing
E as a factor, None is returned. (If the coefficient <code class="docutils literal notranslate"><span class="pre">2*x</span></code> is
desired then the <code class="docutils literal notranslate"><span class="pre">coeff</span></code> method should be used.)</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">E</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">E</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">2*x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">E</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficient</span><span class="p">(</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.coeff" title="sympy.core.expr.Expr.coeff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">coeff</span></code></a></dt><dd><p>return sum of terms have a given factor</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_Add" title="sympy.core.expr.Expr.as_coeff_Add"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_Add</span></code></a></dt><dd><p>separate the additive constant from an expression</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_Mul" title="sympy.core.expr.Expr.as_coeff_Mul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_Mul</span></code></a></dt><dd><p>separate the multiplicative constant from an expression</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_independent" title="sympy.core.expr.Expr.as_independent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_independent</span></code></a></dt><dd><p>separate x-dependent terms/factors from others</p>
</dd>
<dt><a class="reference internal" href="polys/reference.html#sympy.polys.polytools.Poly.coeff_monomial" title="sympy.polys.polytools.Poly.coeff_monomial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.Poly.coeff_monomial</span></code></a></dt><dd><p>efficiently find the single coefficient of a monomial in Poly</p>
</dd>
<dt><a class="reference internal" href="polys/reference.html#sympy.polys.polytools.Poly.nth" title="sympy.polys.polytools.Poly.nth"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.Poly.nth</span></code></a></dt><dd><p>like coeff_monomial but powers of monomial terms are used</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_coefficients_dict">
<span class="sig-name descname"><span class="pre">as_coefficients_dict</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1970-L1994"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_coefficients_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary mapping terms to their Rational coefficient.
Since the dictionary is a defaultdict, inquiries about terms which
were not present will return a coefficient of 0. If an expression is
not an Add it is considered to have a single term.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficients_dict</span><span class="p">()</span>
<span class="go">{1: 4, x: 3, a*x: 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="p">[</span><span class="n">a</span><span class="p">]</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficients_dict</span><span class="p">()</span>
<span class="go">{a*x: 3}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2097-L2152"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>This method should recursively remove a Rational from all arguments
and return that (content) and the new self (primitive). The content
should always be positive and <code class="docutils literal notranslate"><span class="pre">Mul(*foo.as_content_primitive())</span> <span class="pre">==</span> <span class="pre">foo</span></code>.
The primitive need not be in canonical form and should try to preserve
the underlying structure if possible (i.e. expand_mul should not be
applied to self).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<p>The as_content_primitive function is recursive and retains structure:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(2, x + 3*y*(y + 1) + 1)</span>
</pre></div>
</div>
<p>Integer powers will have Rationals extracted from the base:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">6</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(4, (3*x + 1)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">6</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, (2*(3*x + 1))**(2*y))</span>
</pre></div>
</div>
<p>Terms may end up joining once their as_content_primitives are added:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">5</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(11, x*(y + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">3</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(9, x*(y + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">3</span><span class="o">*</span><span class="p">(</span><span class="n">z</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span> <span class="o">+</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, 6.0*x*(y + 1) + 3*z*(y + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">5</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(121, x**2*(y + 1)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.4</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, 4.84*x**2*(y + 1)**2)</span>
</pre></div>
</div>
<p>Radical content can also be factored out of the primitive:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">(</span><span class="n">radical</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(2, sqrt(2)*(1 + 2*sqrt(5)))</span>
</pre></div>
</div>
<p>If clear=False (default is True) then content will not be removed
from an Add if it can be distributed to leave one or more
terms with integer coefficients.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1/2, x + 2*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">(</span><span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(1, x/2 + y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_expr">
<span class="sig-name descname"><span class="pre">as_expr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1645-L1663"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_expr" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a polynomial to a SymPy expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_poly</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">as_expr</span><span class="p">()</span>
<span class="go">x**2 + x*y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_expr</span><span class="p">()</span>
<span class="go">sin(x)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_independent">
<span class="sig-name descname"><span class="pre">as_independent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">deps</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hint</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1733-L1920"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_independent" title="Permalink to this definition">¶</a></dt>
<dd><p>A mostly naive separation of a Mul or Add into arguments that are not
are dependent on deps. To obtain as complete a separation of variables
as possible, use a separation method first, e.g.:</p>
<ul class="simple">
<li><p>separatevars() to change Mul, Add and Pow (including exp) into Mul</p></li>
<li><p>.expand(mul=True) to change Add or Mul into Add</p></li>
<li><p>.expand(log=True) to change log expr into an Add</p></li>
</ul>
<p>The only non-naive thing that is done here is to respect noncommutative
ordering of variables and to always return (0, 0) for <span class="math notranslate nohighlight">\(self\)</span> of zero
regardless of hints.</p>
<p>For nonzero <span class="math notranslate nohighlight">\(self\)</span>, the returned tuple (i, d) has the
following interpretation:</p>
<ul class="simple">
<li><p>i will has no variable that appears in deps</p></li>
<li><p>d will either have terms that contain variables that are in deps, or
be equal to 0 (when self is an Add) or 1 (when self is a Mul)</p></li>
<li><p>if self is an Add then self = i + d</p></li>
<li><p>if self is a Mul then self = i*d</p></li>
<li><p>otherwise (self, S.One) or (S.One, self) is returned.</p></li>
</ul>
<p>To force the expression to be treated as an Add, use the hint as_Add=True</p>
<p class="rubric">Examples</p>
<p>– self is an Add</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">exp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(0, x*y + x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x, x*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(y + z, 2*x*sin(x) + x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">(z, 2*x*sin(x) + x + y)</span>
</pre></div>
</div>
<p>– self is a Mul</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(cos(y), x*sin(x))</span>
</pre></div>
</div>
<p>non-commutative terms cannot always be separated out when self is a Mul</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">,</span> <span class="n">n3</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n1 n2 n3&#39;</span><span class="p">,</span> <span class="n">commutative</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n1</span><span class="o">*</span><span class="n">n2</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">n2</span><span class="p">)</span>
<span class="go">(n1, n1*n2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n2</span><span class="o">*</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n1</span><span class="o">*</span><span class="n">n2</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">n2</span><span class="p">)</span>
<span class="go">(0, n1*n2 + n2*n1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n1</span><span class="o">*</span><span class="n">n2</span><span class="o">*</span><span class="n">n3</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">n1</span><span class="p">)</span>
<span class="go">(1, n1*n2*n3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n1</span><span class="o">*</span><span class="n">n2</span><span class="o">*</span><span class="n">n3</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">n2</span><span class="p">)</span>
<span class="go">(n1, n2*n3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">-</span><span class="n">n1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1, (x - y)*(x - n1))</span>
</pre></div>
</div>
<p>– self is anything else:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1, sin(x))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(sin(x), 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1, exp(x + y))</span>
</pre></div>
</div>
<p>– force self to be treated as an Add:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">as_Add</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(0, 3*x)</span>
</pre></div>
</div>
<p>– force self to be treated as a Mul:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">+</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">as_Add</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(1, x + 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="o">+</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">as_Add</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(1, x - 3)</span>
</pre></div>
</div>
<p>Note how the below differs from the above in making the
constant on the dep term positive.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">y</span><span class="o">*</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="o">+</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(y, x - 3)</span>
</pre></div>
</div>
<dl class="simple">
<dt>– use .as_independent() for true independence testing instead</dt><dd><p>of .has(). The former considers only symbols in the free
symbols while the latter considers all symbols</p>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Integral</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="ow">in</span> <span class="n">I</span><span class="o">.</span><span class="n">free_symbols</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="p">(</span><span class="n">I</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">I</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="p">(</span><span class="n">I</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Note: when trying to get independent terms, a separation method
might need to be used first. In this case, it is important to keep
track of what you send to this routine so you know how to interpret
the returned values</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">separatevars</span><span class="p">,</span> <span class="n">log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">separatevars</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(exp(y), exp(x))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x, x*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">separatevars</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x, y + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x, y + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x, x*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span><span class="o">.</span><span class="n">as_independent</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">(log(a), log(b))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="simplify/simplify.html#sympy.simplify.simplify.separatevars" title="sympy.simplify.simplify.separatevars"><code class="xref py py-obj docutils literal notranslate"><span class="pre">separatevars</span></code></a>, <a class="reference internal" href="#sympy.core.expr.Expr.expand" title="sympy.core.expr.Expr.expand"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand</span></code></a>, <a class="reference internal" href="#sympy.core.add.Add.as_two_terms" title="sympy.core.add.Add.as_two_terms"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.add.Add.as_two_terms</span></code></a>, <a class="reference internal" href="#sympy.core.mul.Mul.as_two_terms" title="sympy.core.mul.Mul.as_two_terms"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.mul.Mul.as_two_terms</span></code></a>, <a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_add" title="sympy.core.expr.Expr.as_coeff_add"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_add</span></code></a>, <a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_mul" title="sympy.core.expr.Expr.as_coeff_mul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_mul</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_leading_term">
<span class="sig-name descname"><span class="pre">as_leading_term</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3411-L3445"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_leading_term" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the leading (nonzero) term of the series expansion of self.</p>
<p>The _eval_as_leading_term routines are used to do this, and they must
always return a non-zero value.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_leading_term</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_leading_term</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">x**(-2)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_numer_denom">
<span class="sig-name descname"><span class="pre">as_numer_denom</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2154-L2166"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_numer_denom" title="Permalink to this definition">¶</a></dt>
<dd><p>expression -&gt; a/b -&gt; a, b</p>
<p>This is just a stub that should be defined by
an object’s class methods to get anything else.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.normal" title="sympy.core.expr.Expr.normal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">normal</span></code></a></dt><dd><p>return <code class="docutils literal notranslate"><span class="pre">a/b</span></code> instead of <code class="docutils literal notranslate"><span class="pre">(a,</span> <span class="pre">b)</span></code></p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_ordered_factors">
<span class="sig-name descname"><span class="pre">as_ordered_factors</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1105-L1107"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_ordered_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Return list of ordered factors (if Mul) else [self].</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_ordered_terms">
<span class="sig-name descname"><span class="pre">as_ordered_terms</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1140-L1192"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_ordered_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform an expression to an ordered list of terms.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">as_ordered_terms</span><span class="p">()</span>
<span class="go">[sin(x)**2*cos(x), sin(x)**2, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_poly">
<span class="sig-name descname"><span class="pre">as_poly</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1109-L1138"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_poly" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts <code class="docutils literal notranslate"><span class="pre">self</span></code> to a polynomial or returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p class="rubric">Explanation</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">((</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_poly</span><span class="p">())</span>
<span class="go">Poly(x**2 + x*y, x, y, domain=&#39;ZZ&#39;)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">((</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_poly</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="go">Poly(x**2 + x*y, x, y, domain=&#39;ZZ&#39;)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">((</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">as_poly</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="go">None</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_powers_dict">
<span class="sig-name descname"><span class="pre">as_powers_dict</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1951-L1968"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_powers_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return self as a dictionary of factors with each factor being
treated as a power. The keys are the bases of the factors and the
values, the corresponding exponents. The resulting dictionary should
be used with caution if the expression is a Mul and contains non-
commutative factors since the order that they appeared will be lost in
the dictionary.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_ordered_factors" title="sympy.core.expr.Expr.as_ordered_factors"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_ordered_factors</span></code></a></dt><dd><p>An alternative for noncommutative applications, returning an ordered list of factors.</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.args_cnc" title="sympy.core.expr.Expr.args_cnc"><code class="xref py py-obj docutils literal notranslate"><span class="pre">args_cnc</span></code></a></dt><dd><p>Similar to as_ordered_factors, but guarantees separation of commutative and noncommutative factors.</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_real_imag">
<span class="sig-name descname"><span class="pre">as_real_imag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1922-L1949"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_real_imag" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs complex expansion on ‘self’ and returns a tuple
containing collected both real and imaginary parts. This
method can’t be confused with re() and im() functions,
which does not perform complex expansion at evaluation.</p>
<p>However it is possible to expand both re() and im()
functions and get exactly the same results as with
a single call to this function.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">I</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">as_real_imag</span><span class="p">()</span>
<span class="go">(x, y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">z</span><span class="p">,</span> <span class="n">w</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">z</span> <span class="o">+</span> <span class="n">w</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">as_real_imag</span><span class="p">()</span>
<span class="go">(re(z) - im(w), re(w) + im(z))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.as_terms">
<span class="sig-name descname"><span class="pre">as_terms</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1194-L1248"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.as_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform an expression to a list of terms.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.aseries">
<span class="sig-name descname"><span class="pre">aseries</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bound</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3085-L3235"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.aseries" title="Permalink to this definition">¶</a></dt>
<dd><p>Asymptotic Series expansion of self.
This is equivalent to <code class="docutils literal notranslate"><span class="pre">self.series(x,</span> <span class="pre">oo,</span> <span class="pre">n)</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>self</strong> : Expression</p>
<blockquote>
<div><p>The expression whose series is to be expanded.</p>
</div></blockquote>
<p><strong>x</strong> : Symbol</p>
<blockquote>
<div><p>It is the variable of the expression to be calculated.</p>
</div></blockquote>
<p><strong>n</strong> : Value</p>
<blockquote>
<div><p>The number of terms upto which the series is to be expanded.</p>
</div></blockquote>
<p><strong>hir</strong> : Boolean</p>
<blockquote>
<div><p>Set this parameter to be True to produce hierarchical series.
It stops the recursion at an early level and may provide nicer
and more useful results.</p>
</div></blockquote>
<p><strong>bound</strong> : Value, Integer</p>
<blockquote>
<div><p>Use the <code class="docutils literal notranslate"><span class="pre">bound</span></code> parameter to give limit on rewriting
coefficients in its normalised form.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Expr</p>
<blockquote>
<div><p>Asymptotic series expansion of the expression.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">exp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">))</span> <span class="o">-</span> <span class="n">sin</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">aseries</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">aseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">hir</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">-exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">aseries</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">exp(exp(x)/(1 - 1/x))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">aseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">bound</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> 
<span class="go">exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
to look for the most rapidly varying subexpression w of a given expression f and then expands f
in a series in w. Then same thing is recursively done on the leading coefficient
till we get constant coefficients.</p>
<p>If the most rapidly varying subexpression of a given expression f is f itself,
the algorithm tries to find a normalised representation of the mrv set and rewrites f
using this normalised representation.</p>
<p>If the expansion contains an order term, it will be either <code class="docutils literal notranslate"><span class="pre">O(x</span> <span class="pre">**</span> <span class="pre">(-n))</span></code> or <code class="docutils literal notranslate"><span class="pre">O(w</span> <span class="pre">**</span> <span class="pre">(-n))</span></code>
where <code class="docutils literal notranslate"><span class="pre">w</span></code> belongs to the most rapidly varying expression of <code class="docutils literal notranslate"><span class="pre">self</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.aseries" title="sympy.core.expr.Expr.aseries"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Expr.aseries</span></code></a></dt><dd><p>See the docstring of this function for complete details of this wrapper.</p>
</dd>
</dl>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r101"><span class="brackets"><a class="fn-backref" href="#id18">R101</a></span></dt>
<dd><p>A New Algorithm for Computing Asymptotic Series - Dominik Gruntz</p>
</dd>
<dt class="label" id="r102"><span class="brackets"><a class="fn-backref" href="#id19">R102</a></span></dt>
<dd><p>Gruntz thesis - p90</p>
</dd>
<dt class="label" id="r103"><span class="brackets"><a class="fn-backref" href="#id20">R103</a></span></dt>
<dd><p><a class="reference external" href="http://en.wikipedia.org/wiki/Asymptotic_expansion">http://en.wikipedia.org/wiki/Asymptotic_expansion</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.cancel">
<span class="sig-name descname"><span class="pre">cancel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3728-L3731"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.cancel" title="Permalink to this definition">¶</a></dt>
<dd><p>See the cancel function in sympy.polys</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.coeff">
<span class="sig-name descname"><span class="pre">coeff</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1375-L1643"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.coeff" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the coefficient from the term(s) containing <code class="docutils literal notranslate"><span class="pre">x**n</span></code>. If <code class="docutils literal notranslate"><span class="pre">n</span></code>
is zero then all terms independent of <code class="docutils literal notranslate"><span class="pre">x</span></code> will be returned.</p>
<p class="rubric">Explanation</p>
<p>When <code class="docutils literal notranslate"><span class="pre">x</span></code> is noncommutative, the coefficient to the left (default) or
right of <code class="docutils literal notranslate"><span class="pre">x</span></code> can be returned. The keyword ‘right’ is ignored when
<code class="docutils literal notranslate"><span class="pre">x</span></code> is commutative.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
</pre></div>
</div>
<p>You can select terms that have an explicit negative in front of them:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">2*y</span>
</pre></div>
</div>
<p>You can select terms with no Rational coefficient:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>You can select terms independent of x by making n=0; in this case
expr.as_independent(x)[0] is returned (and 0 will be returned instead
of None):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span>
<span class="go">x**3 + 3*x**2 + 3*x + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">eq</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">reversed</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span>
<span class="go">[1, 3, 3, 2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">-=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">eq</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">reversed</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span>
<span class="go">[1, 3, 3, 0]</span>
</pre></div>
</div>
<p>You can select terms that have a numerical term in front of them:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">-y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="go">x</span>
</pre></div>
</div>
<p>The matching is exact:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">z</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">z</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
from the following:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">z</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<p>If such factoring is desired, factor_terms can be used first:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factor_terms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">z</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">z*(y + 1) + 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">o</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n m o&#39;</span><span class="p">,</span> <span class="n">commutative</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">*</span><span class="n">m</span> <span class="o">+</span> <span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="o">*</span><span class="n">m</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="c1"># = (1 + m)*n*m</span>
<span class="go">1 + m</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">*</span><span class="n">m</span> <span class="o">+</span> <span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="o">*</span><span class="n">m</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># = (1 + m)*n*m</span>
<span class="go">m</span>
</pre></div>
</div>
<p>If there is more than one possible coefficient 0 is returned:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">*</span><span class="n">m</span> <span class="o">+</span> <span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>If there is only one possible coefficient, it is returned:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">*</span><span class="n">m</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">*</span><span class="n">m</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">coeff</span><span class="p">(</span><span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_coefficient" title="sympy.core.expr.Expr.as_coefficient"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coefficient</span></code></a></dt><dd><p>separate the expression into a coefficient and factor</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_Add" title="sympy.core.expr.Expr.as_coeff_Add"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_Add</span></code></a></dt><dd><p>separate the additive constant from an expression</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_coeff_Mul" title="sympy.core.expr.Expr.as_coeff_Mul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coeff_Mul</span></code></a></dt><dd><p>separate the multiplicative constant from an expression</p>
</dd>
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_independent" title="sympy.core.expr.Expr.as_independent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_independent</span></code></a></dt><dd><p>separate x-dependent terms/factors from others</p>
</dd>
<dt><a class="reference internal" href="polys/reference.html#sympy.polys.polytools.Poly.coeff_monomial" title="sympy.polys.polytools.Poly.coeff_monomial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.Poly.coeff_monomial</span></code></a></dt><dd><p>efficiently find the single coefficient of a monomial in Poly</p>
</dd>
<dt><a class="reference internal" href="polys/reference.html#sympy.polys.polytools.Poly.nth" title="sympy.polys.polytools.Poly.nth"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.Poly.nth</span></code></a></dt><dd><p>like coeff_monomial but powers of monomial terms are used</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.collect">
<span class="sig-name descname"><span class="pre">collect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">syms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exact</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">distribute_order_term</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3678-L3681"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.collect" title="Permalink to this definition">¶</a></dt>
<dd><p>See the collect function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.combsimp">
<span class="sig-name descname"><span class="pre">combsimp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3713-L3716"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.combsimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the combsimp function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.compute_leading_term">
<span class="sig-name descname"><span class="pre">compute_leading_term</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3388-L3409"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.compute_leading_term" title="Permalink to this definition">¶</a></dt>
<dd><p>as_leading_term is only allowed for results of .series()
This is a wrapper to compute a series first.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.conjugate">
<span class="sig-name descname"><span class="pre">conjugate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1010-L1013"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.conjugate" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the complex conjugate of ‘self’.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.could_extract_minus_sign">
<span class="sig-name descname"><span class="pre">could_extract_minus_sign</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2456-L2500"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.could_extract_minus_sign" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if self is not in a canonical form with respect
to its sign.</p>
<p>For most expressions, e, there will be a difference in e and -e.
When there is, True will be returned for one and False for the
other; False will be returned if there is no difference.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">-</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="n">i</span><span class="o">.</span><span class="n">could_extract_minus_sign</span><span class="p">()</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="o">-</span><span class="n">e</span><span class="p">)}</span>
<span class="go">{False, True}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.count_ops">
<span class="sig-name descname"><span class="pre">count_ops</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">visual</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1304-L1307"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.count_ops" title="Permalink to this definition">¶</a></dt>
<dd><p>wrapper for count_ops that returns the operation count.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.equals">
<span class="sig-name descname"><span class="pre">equals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">failing_expression</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L714-L847"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.equals" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if self == other, False if it doesn’t, or None. If
failing_expression is True then the expression which did not simplify
to a 0 will be returned instead of None.</p>
<p class="rubric">Explanation</p>
<p>If <code class="docutils literal notranslate"><span class="pre">self</span></code> is a Number (or complex number) that is not zero, then
the result is False.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">self</span></code> is a number and has not evaluated to zero, evalf will be
used to test whether the expression evaluates to zero. If it does so
and the result has significance (i.e. the precision is either -1, for
a Rational result, or is greater than 1) then the evalf value will be
used to return True or False.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.expand">
<span class="sig-name descname"><span class="pre">expand</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">modulus</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">power_base</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">power_exp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mul</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multinomial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">basic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3569-L3657"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.expand" title="Permalink to this definition">¶</a></dt>
<dd><p>Expand an expression using hints.</p>
<p>See the docstring of the expand() function in sympy.core.function for
more information.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.expr_free_symbols">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">expr_free_symbols</span></span><a class="headerlink" href="#sympy.core.expr.Expr.expr_free_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Like <code class="docutils literal notranslate"><span class="pre">free_symbols</span></code>, but returns the free symbols only if
they are contained in an expression node.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.exceptions</span> <span class="kn">import</span> <span class="n">SymPyDeprecationWarning</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="n">SymPyDeprecationWarning</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expr_free_symbols</span>
<span class="go">{x, y}</span>
</pre></div>
</div>
<p>If the expression is contained in a non-expression object, don’t return
the free symbols. Compare:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Tuple</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">Tuple</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">expr_free_symbols</span>
<span class="go">set()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">free_symbols</span>
<span class="go">{x, y}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.extract_additively">
<span class="sig-name descname"><span class="pre">extract_additively</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">c</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2319-L2422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.extract_additively" title="Permalink to this definition">¶</a></dt>
<dd><p>Return self - c if it’s possible to subtract c from self and
make all matching coefficients move towards zero, else return None.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">y</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">(x + 1)*(x + 2*y) + 3</span>
</pre></div>
</div>
<p>Sometimes auto-expansion will return a less simplified result
than desired; gcd_terms might be used in such cases:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">gcd_terms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">extract_additively</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">x*(4*y + 3) + y</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.expr.Expr.extract_multiplicatively" title="sympy.core.expr.Expr.extract_multiplicatively"><code class="xref py py-obj docutils literal notranslate"><span class="pre">extract_multiplicatively</span></code></a>, <a class="reference internal" href="#sympy.core.expr.Expr.coeff" title="sympy.core.expr.Expr.coeff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">coeff</span></code></a>, <a class="reference internal" href="#sympy.core.expr.Expr.as_coefficient" title="sympy.core.expr.Expr.as_coefficient"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_coefficient</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.extract_branch_factor">
<span class="sig-name descname"><span class="pre">extract_branch_factor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">allow_half</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2502-L2573"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.extract_branch_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>Try to write self as <code class="docutils literal notranslate"><span class="pre">exp_polar(2*pi*I*n)*z</span></code> in a nice way.
Return (z, n).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp_polar</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(exp_polar(I*pi), 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(1, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="o">-</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(exp_polar(I*pi), -1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(exp_polar(x + I*pi), 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">y</span><span class="o">*</span><span class="n">exp_polar</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">*</span><span class="n">exp_polar</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">I</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(y*exp_polar(2*pi*x), -1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="o">-</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">()</span>
<span class="go">(exp_polar(-I*pi/2), 0)</span>
</pre></div>
</div>
<p>If allow_half is True, also extract exp_polar(I*pi):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">(</span><span class="n">allow_half</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(1, 1/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">(</span><span class="n">allow_half</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(1, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">(</span><span class="n">allow_half</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(1, 3/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp_polar</span><span class="p">(</span><span class="o">-</span><span class="n">I</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">.</span><span class="n">extract_branch_factor</span><span class="p">(</span><span class="n">allow_half</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(1, -1/2)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.extract_multiplicatively">
<span class="sig-name descname"><span class="pre">extract_multiplicatively</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">c</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2186-L2317"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.extract_multiplicatively" title="Permalink to this definition">¶</a></dt>
<dd><p>Return None if it’s not possible to make self in the form
c * something in a nice way, i.e. preserving the properties
of arguments of self.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">extract_multiplicatively</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span> <span class="n">y</span><span class="p">)</span>
<span class="go">x*y**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">extract_multiplicatively</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">4</span> <span class="o">*</span> <span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">extract_multiplicatively</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">extract_multiplicatively</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">extract_multiplicatively</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">x/6</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.factor">
<span class="sig-name descname"><span class="pre">factor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3723-L3726"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.factor" title="Permalink to this definition">¶</a></dt>
<dd><p>See the factor() function in sympy.polys.polytools</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.fourier_series">
<span class="sig-name descname"><span class="pre">fourier_series</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">limits</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3510-L3518"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.fourier_series" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute fourier sine/cosine series of self.</p>
<p>See the docstring of the <a class="reference internal" href="#sympy.core.expr.Expr.fourier_series" title="sympy.core.expr.Expr.fourier_series"><code class="xref py py-func docutils literal notranslate"><span class="pre">fourier_series()</span></code></a> in sympy.series.fourier
for more information.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.fps">
<span class="sig-name descname"><span class="pre">fps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hyper</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">4</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3498-L3508"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.fps" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute formal power power series of self.</p>
<p>See the docstring of the <a class="reference internal" href="#sympy.core.expr.Expr.fps" title="sympy.core.expr.Expr.fps"><code class="xref py py-func docutils literal notranslate"><span class="pre">fps()</span></code></a> function in sympy.series.formal for
more information.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.gammasimp">
<span class="sig-name descname"><span class="pre">gammasimp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3718-L3721"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.gammasimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the gammasimp function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.getO">
<span class="sig-name descname"><span class="pre">getO</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1254-L1256"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.getO" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the additive O(..) symbol if there is one, else None.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.getn">
<span class="sig-name descname"><span class="pre">getn</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1258-L1302"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.getn" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the order of the expression.</p>
<p class="rubric">Explanation</p>
<p>The order is determined either from the O(…) term. If there
is no O(…) term, it returns None.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">O</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">getn</span><span class="p">()</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">getn</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.integrate">
<span class="sig-name descname"><span class="pre">integrate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3663-L3666"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.integrate" title="Permalink to this definition">¶</a></dt>
<dd><p>See the integrate function in sympy.integrals</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.invert">
<span class="sig-name descname"><span class="pre">invert</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3733-L3745"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.invert" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the multiplicative inverse of <code class="docutils literal notranslate"><span class="pre">self</span></code> mod <code class="docutils literal notranslate"><span class="pre">g</span></code>
where <code class="docutils literal notranslate"><span class="pre">self</span></code> (and <code class="docutils literal notranslate"><span class="pre">g</span></code>) may be symbolic expressions).</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.mod_inverse" title="sympy.core.numbers.mod_inverse"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.numbers.mod_inverse</span></code></a>, <a class="reference internal" href="polys/reference.html#sympy.polys.polytools.invert" title="sympy.polys.polytools.invert"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.invert</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_algebraic_expr">
<span class="sig-name descname"><span class="pre">is_algebraic_expr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">syms</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2788-L2839"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.is_algebraic_expr" title="Permalink to this definition">¶</a></dt>
<dd><p>This tests whether a given expression is algebraic or not, in the
given symbols, syms. When syms is not given, all free symbols
will be used. The rational function does not have to be in expanded
or in any kind of canonical form.</p>
<p>This function returns False for expressions that are “algebraic
expressions” with symbolic exponents. This is a simple extension to the
is_rational_function, including rational exponentiation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_algebraic_expr</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<p>This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be an algebraic
expression to become one.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp</span><span class="p">,</span> <span class="n">factor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_algebraic_expr</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">.</span><span class="n">is_algebraic_expr</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.expr.Expr.is_rational_function" title="sympy.core.expr.Expr.is_rational_function"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_rational_function</span></code></a></p>
</div>
<p class="rubric">References</p>
<ul class="simple">
<li><p><a class="reference external" href="https://en.wikipedia.org/wiki/Algebraic_expression">https://en.wikipedia.org/wiki/Algebraic_expression</a></p></li>
</ul>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_constant">
<span class="sig-name descname"><span class="pre">is_constant</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">wrt</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">flags</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L539-L712"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.is_constant" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if self is constant, False if not, or None if
the constancy could not be determined conclusively.</p>
<p class="rubric">Explanation</p>
<p>If an expression has no free symbols then it is a constant. If
there are free symbols it is possible that the expression is a
constant, perhaps (but not necessarily) zero. To test such
expressions, a few strategies are tried:</p>
<p>1) numerical evaluation at two random points. If two such evaluations
give two different values and the values have a precision greater than
1 then self is not constant. If the evaluations agree or could not be
obtained with any precision, no decision is made. The numerical testing
is done only if <code class="docutils literal notranslate"><span class="pre">wrt</span></code> is different than the free symbols.</p>
<p>2) differentiation with respect to variables in ‘wrt’ (or all free
symbols if omitted) to see if the expression is constant or not. This
will not always lead to an expression that is zero even though an
expression is constant (see added test in test_expr.py). If
all derivatives are zero then self is constant with respect to the
given symbols.</p>
<p>3) finding out zeros of denominator expression with free_symbols.
It won’t be constant if there are zeros. It gives more negative
answers for expression that are not constant.</p>
<p>If neither evaluation nor differentiation can prove the expression is
constant, None is returned unless two numerical values happened to be
the same and the flag <code class="docutils literal notranslate"><span class="pre">failing_number</span></code> is True – in that case the
numerical value will be returned.</p>
<p>If flag simplify=False is passed, self will not be simplified;
the default is True since self should be simplified before testing.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="n">a</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">a</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">pi</span><span class="p">,</span> <span class="n">a</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span> <span class="o">==</span> <span class="n">eq</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">pi</span><span class="p">,</span> <span class="n">a</span><span class="p">:</span> <span class="mi">3</span><span class="p">})</span> <span class="o">==</span> <span class="mi">0</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">0</span><span class="o">**</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">one</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">one</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">one</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">is_constant</span><span class="p">()</span> <span class="ow">in</span> <span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="c1"># could be 0 or 1</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_meromorphic">
<span class="sig-name descname"><span class="pre">is_meromorphic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2722-L2781"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.is_meromorphic" title="Permalink to this definition">¶</a></dt>
<dd><p>This tests whether an expression is meromorphic as
a function of the given symbol <code class="docutils literal notranslate"><span class="pre">x</span></code> at the point <code class="docutils literal notranslate"><span class="pre">a</span></code>.</p>
<p>This method is intended as a quick test that will return
None if no decision can be made without simplification or
more detailed analysis.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">zoo</span><span class="p">,</span> <span class="n">log</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">zoo</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="n">log</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">zoo</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">h</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">h</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">zoo</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Multivalued functions are considered meromorphic when their
branches are meromorphic. Thus most functions are meromorphic
everywhere except at essential singularities and branch points.
In particular, they will be meromorphic also on branch cuts
except at their endpoints.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_meromorphic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_number">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_number</span></span><a class="headerlink" href="#sympy.core.expr.Expr.is_number" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if <code class="docutils literal notranslate"><span class="pre">self</span></code> has no free symbols and no
undefined functions (AppliedUndef, to be precise). It will be
faster than <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">not</span> <span class="pre">self.free_symbols</span></code>, however, since
<code class="docutils literal notranslate"><span class="pre">is_number</span></code> will fail as soon as it hits a free symbol
or undefined function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integral</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="n">Integral</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="n">Integral</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Not all numbers are Numbers in the SymPy sense:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span><span class="o">.</span><span class="n">is_number</span><span class="p">,</span> <span class="n">pi</span><span class="o">.</span><span class="n">is_Number</span>
<span class="go">(True, False)</span>
</pre></div>
</div>
<p>If something is a number it should evaluate to a number with
real and imaginary parts that are Numbers; the result may not
be comparable, however, since the real and/or imaginary part
of the result may not have precision.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_number</span> <span class="ow">and</span> <span class="n">cos</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_comparable</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span><span class="o">.</span><span class="n">is_number</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span><span class="o">.</span><span class="n">is_comparable</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.basic.Basic.is_comparable" title="sympy.core.basic.Basic.is_comparable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.basic.Basic.is_comparable</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_polynomial">
<span class="sig-name descname"><span class="pre">is_polynomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">syms</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2580-L2646"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.is_polynomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if self is a polynomial in syms and False otherwise.</p>
<p>This checks if self is an exact polynomial in syms.  This function
returns False for expressions that are “polynomials” with symbolic
exponents.  Thus, you should be able to apply polynomial algorithms to
expressions for which this returns True, and Poly(expr, *syms) should
work if and only if expr.is_polynomial(*syms) returns True. The
polynomial does not have to be in expanded form.  If no symbols are
given, all free symbols in the expression will be used.</p>
<p>This is not part of the assumptions system.  You cannot do
Symbol(‘z’, polynomial=True).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">nonnegative</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p>This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be a polynomial to
become one.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">factor</span><span class="p">,</span> <span class="n">cancel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">y + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="p">(</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cancel</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">y + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cancel</span><span class="p">(</span><span class="n">b</span><span class="p">)</span><span class="o">.</span><span class="n">is_polynomial</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>See also .is_rational_function()</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.is_rational_function">
<span class="sig-name descname"><span class="pre">is_rational_function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">syms</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2653-L2716"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.is_rational_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Test whether function is a ratio of two polynomials in the given
symbols, syms. When syms is not given, all free symbols will be used.
The rational function does not have to be in expanded or in any kind of
canonical form.</p>
<p>This function returns False for expressions that are “rational
functions” with symbolic exponents.  Thus, you should be able to call
.as_numer_denom() and apply polynomial algorithms to the result for
expressions for which this returns True.</p>
<p>This is not part of the assumptions system.  You cannot do
Symbol(‘z’, rational_function=True).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p>This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be a rational function
to become one.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">factor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">(y + 1)/y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="o">.</span><span class="n">is_rational_function</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>See also is_algebraic_expr().</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.leadterm">
<span class="sig-name descname"><span class="pre">leadterm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3462-L3488"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.leadterm" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the leading term a*x**b as a tuple (a, b).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">x</span><span class="o">+</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">leadterm</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">+</span><span class="n">x</span><span class="o">+</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">leadterm</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">(1, -2)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.limit">
<span class="sig-name descname"><span class="pre">limit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3382-L3386"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute limit x-&gt;xlim.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.lseries">
<span class="sig-name descname"><span class="pre">lseries</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3249-L3267"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.lseries" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper for series yielding an iterator of the terms of the series.</p>
<p>Note: an infinite series will yield an infinite iterator. The following,
for exaxmple, will never terminate. It will just keep printing terms
of the sin(x) series:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">term</span> <span class="ow">in</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">lseries</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="nb">print</span> <span class="n">term</span>
</pre></div>
</div>
<p>The advantage of lseries() over nseries() is that many times you are
just interested in the next term in the series (i.e. the first term for
example), but you don’t know how many you should ask for in nseries()
using the “n” parameter.</p>
<p>See also nseries().</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.normal">
<span class="sig-name descname"><span class="pre">normal</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2168-L2184"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.normal" title="Permalink to this definition">¶</a></dt>
<dd><p>expression -&gt; a/b</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.core.expr.Expr.as_numer_denom" title="sympy.core.expr.Expr.as_numer_denom"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_numer_denom</span></code></a></dt><dd><p>return <code class="docutils literal notranslate"><span class="pre">(a,</span> <span class="pre">b)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">a/b</span></code></p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.nseries">
<span class="sig-name descname"><span class="pre">nseries</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3298-L3363"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.nseries" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper to _eval_nseries if assumptions allow, else to series.</p>
<p>If x is given, x0 is 0, dir=’+’, and self has x, then _eval_nseries is
called. This calculates “n” terms in the innermost expressions and
then builds up the final series just by “cross-multiplying” everything
out.</p>
<p>The optional <code class="docutils literal notranslate"><span class="pre">logx</span></code> parameter can be used to replace any log(x) in the
returned series with a symbolic value to avoid evaluating log(x) at 0. A
symbol to use in place of log(x) should be provided.</p>
<p>Advantage – it’s fast, because we don’t have to determine how many
terms we need to calculate in advance.</p>
<p>Disadvantage – you may end up with less terms than you may have
expected, but the O(x**n) term appended will always be correct and
so the result, though perhaps shorter, will also be correct.</p>
<p>If any of those assumptions is not met, this is treated like a
wrapper to series which will try harder to return the correct
number of terms.</p>
<p>See also lseries().</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">log</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="go">x - x**3/6 + x**5/120 + O(x**6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">x - x**2/2 + x**3/3 - x**4/4 + O(x**5)</span>
</pre></div>
</div>
<p>Handling of the <code class="docutils literal notranslate"><span class="pre">logx</span></code> parameter — in the following example the
expansion fails since <code class="docutils literal notranslate"><span class="pre">sin</span></code> does not have an asymptotic expansion
at -oo (the limit of log(x) as x approaches 0):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">PoleError</span>: <span class="n">...</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logx</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;logx&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="n">logx</span><span class="o">=</span><span class="n">logx</span><span class="p">)</span>
<span class="go">sin(logx)</span>
</pre></div>
</div>
<p>In the following example, the expansion works but gives only an Order term
unless the <code class="docutils literal notranslate"><span class="pre">logx</span></code> parameter is used:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">O(log(x)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">nseries</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">logx</span><span class="o">=</span><span class="n">logx</span><span class="p">)</span>
<span class="go">exp(logx*y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.nsimplify">
<span class="sig-name descname"><span class="pre">nsimplify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">constants</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tolerance</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3668-L3671"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.nsimplify" title="Permalink to this definition">¶</a></dt>
<dd><p>See the nsimplify function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.powsimp">
<span class="sig-name descname"><span class="pre">powsimp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3708-L3711"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.powsimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the powsimp function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.primitive">
<span class="sig-name descname"><span class="pre">primitive</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2071-L2095"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the positive Rational that can be extracted non-recursively
from every term of self (i.e., self is treated like an Add). This is
like the as_coeff_Mul() method but primitive always extracts a positive
Rational (never a negative or a Float).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(3, (x + 1)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="p">(</span><span class="mi">6</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">);</span> <span class="n">a</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(2, 3*x + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="p">);</span> <span class="n">b</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(1/2, x + 6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span> <span class="o">==</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.radsimp">
<span class="sig-name descname"><span class="pre">radsimp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3703-L3706"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.radsimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the radsimp function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.ratsimp">
<span class="sig-name descname"><span class="pre">ratsimp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3693-L3696"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.ratsimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the ratsimp function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.removeO">
<span class="sig-name descname"><span class="pre">removeO</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L1250-L1252"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.removeO" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the additive O(..) symbol if there is one</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.round">
<span class="sig-name descname"><span class="pre">round</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3747-L3893"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.round" title="Permalink to this definition">¶</a></dt>
<dd><p>Return x rounded to the given decimal place.</p>
<p>If a complex number would results, apply round to the real
and imaginary components of the number.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">Number</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span><span class="o">.</span><span class="n">round</span><span class="p">()</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">3.14</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span> <span class="o">+</span> <span class="n">E</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">()</span>
<span class="go">6 + 3*I</span>
</pre></div>
</div>
<p>The round method has a chopping effect:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span> <span class="o">+</span> <span class="n">I</span><span class="o">/</span><span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">()</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">10</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">()</span>
<span class="go">2*I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">10</span> <span class="o">+</span> <span class="n">E</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">0.31 + 2.72*I</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The Python <code class="docutils literal notranslate"><span class="pre">round</span></code> function uses the SymPy <code class="docutils literal notranslate"><span class="pre">round</span></code> method so it
will always return a SymPy number (not a Python float or int):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">123</span><span class="p">),</span> <span class="o">-</span><span class="mi">2</span><span class="p">),</span> <span class="n">Number</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.separate">
<span class="sig-name descname"><span class="pre">separate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3673-L3676"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.separate" title="Permalink to this definition">¶</a></dt>
<dd><p>See the separate function in sympy.simplify</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.series">
<span class="sig-name descname"><span class="pre">series</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L2845-L3083"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.series" title="Permalink to this definition">¶</a></dt>
<dd><p>Series expansion of “self” around <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">x0</span></code> yielding either terms of
the series one by one (the lazy series given when n=None), else
all the terms at once when n != None.</p>
<p>Returns the series expansion of “self” around the point <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">x0</span></code>
with respect to <code class="docutils literal notranslate"><span class="pre">x</span></code> up to <code class="docutils literal notranslate"><span class="pre">O((x</span> <span class="pre">-</span> <span class="pre">x0)**n,</span> <span class="pre">x,</span> <span class="pre">x0)</span></code> (default n is 6).</p>
<p>If <code class="docutils literal notranslate"><span class="pre">x=None</span></code> and <code class="docutils literal notranslate"><span class="pre">self</span></code> is univariate, the univariate symbol will
be supplied, otherwise an error will be raised.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expression</p>
<blockquote>
<div><p>The expression whose series is to be expanded.</p>
</div></blockquote>
<p><strong>x</strong> : Symbol</p>
<blockquote>
<div><p>It is the variable of the expression to be calculated.</p>
</div></blockquote>
<p><strong>x0</strong> : Value</p>
<blockquote>
<div><p>The value around which <code class="docutils literal notranslate"><span class="pre">x</span></code> is calculated. Can be any value
from <code class="docutils literal notranslate"><span class="pre">-oo</span></code> to <code class="docutils literal notranslate"><span class="pre">oo</span></code>.</p>
</div></blockquote>
<p><strong>n</strong> : Value</p>
<blockquote>
<div><p>The number of terms upto which the series is to be expanded.</p>
</div></blockquote>
<p><strong>dir</strong> : String, optional</p>
<blockquote>
<div><p>The series-expansion can be bi-directional. If <code class="docutils literal notranslate"><span class="pre">dir=&quot;+&quot;</span></code>,
then (x-&gt;x0+). If <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;,</span> <span class="pre">then</span> <span class="pre">(x-&gt;x0-).</span> <span class="pre">For</span> <span class="pre">infinite</span>
<span class="pre">``x0</span></code> (<code class="docutils literal notranslate"><span class="pre">oo</span></code> or <code class="docutils literal notranslate"><span class="pre">-oo</span></code>), the <code class="docutils literal notranslate"><span class="pre">dir</span></code> argument is determined
from the direction of the infinity (i.e., <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;</span></code> for
<code class="docutils literal notranslate"><span class="pre">oo</span></code>).</p>
</div></blockquote>
<p><strong>logx</strong> : optional</p>
<blockquote>
<div><p>It is used to replace any log(x) in the returned series with a
symbolic value rather than evaluating the actual value.</p>
</div></blockquote>
<p><strong>cdir</strong> : optional</p>
<blockquote>
<div><p>It stands for complex direction, and indicates the direction
from which the expansion needs to be evaluated.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>Expr</strong> : Expression</p>
<blockquote>
<div><p>Series expansion of the expression about x0</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>TypeError</strong></p>
<blockquote>
<div><p>If “n” and “x0” are infinity objects</p>
</div></blockquote>
<p><strong>PoleError</strong></p>
<blockquote>
<div><p>If “x0” is an infinity object</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">tan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">()</span>
<span class="go">1 - x**2/2 + x**4/24 + O(x**6)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="go">1 - x**2/2 + O(x**4)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x0</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="go">cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="go">cos(x + 1) - y*sin(x + 1) + O(y**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="go">cos(exp(y)) - x*sin(exp(y)) + O(x**2)</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">n=None</span></code> then a generator of the series terms will be returned.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">term</span><span class="o">=</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="nb">next</span><span class="p">(</span><span class="n">term</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">)]</span>
<span class="go">[1, -x**2/2]</span>
</pre></div>
</div>
<p>For <code class="docutils literal notranslate"><span class="pre">dir=+</span></code> (default) the series is calculated from the right and
for <code class="docutils literal notranslate"><span class="pre">dir=-</span></code> the series from the left. For smooth functions this
flag will not alter the results.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="nb">dir</span><span class="o">=</span><span class="s2">&quot;+&quot;</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="nb">dir</span><span class="o">=</span><span class="s2">&quot;-&quot;</span><span class="p">)</span>
<span class="go">-x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">tan</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;+&quot;</span><span class="p">)</span>
<span class="go">tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +</span>
<span class="go">(x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +</span>
<span class="go">5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +</span>
<span class="go">2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;-&quot;</span><span class="p">)</span>
<span class="go">tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))</span>
<span class="go">+ O((x - 2)**3, (x, 2))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.taylor_term">
<span class="sig-name descname"><span class="pre">taylor_term</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">previous_terms</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3238-L3247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.taylor_term" title="Permalink to this definition">¶</a></dt>
<dd><p>General method for the taylor term.</p>
<p>This method is slow, because it differentiates n-times. Subclasses can
redefine it to make it faster by using the “previous_terms”.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.together">
<span class="sig-name descname"><span class="pre">together</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3683-L3686"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.together" title="Permalink to this definition">¶</a></dt>
<dd><p>See the together function in sympy.polys</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.expr.Expr.trigsimp">
<span class="sig-name descname"><span class="pre">trigsimp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3698-L3701"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.Expr.trigsimp" title="Permalink to this definition">¶</a></dt>
<dd><p>See the trigsimp function in sympy.simplify</p>
</dd></dl>

</dd></dl>

</section>
<section id="unevaluatedexpr">
<h3>UnevaluatedExpr<a class="headerlink" href="#unevaluatedexpr" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.expr.UnevaluatedExpr">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.expr.</span></span><span class="sig-name descname"><span class="pre">UnevaluatedExpr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3986-L4011"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.UnevaluatedExpr" title="Permalink to this definition">¶</a></dt>
<dd><p>Expression that is not evaluated unless released.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">UnevaluatedExpr</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">*</span><span class="n">UnevaluatedExpr</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span>
<span class="go">x*1/x</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="atomicexpr">
<h3>AtomicExpr<a class="headerlink" href="#atomicexpr" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.expr.AtomicExpr">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.expr.</span></span><span class="sig-name descname"><span class="pre">AtomicExpr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/expr.py#L3902-L3952"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.expr.AtomicExpr" title="Permalink to this definition">¶</a></dt>
<dd><p>A parent class for object which are both atoms and Exprs.</p>
<p>For example: Symbol, Number, Rational, Integer, …
But not: Add, Mul, Pow, …</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.symbol">
<span id="symbol"></span><h2>symbol<a class="headerlink" href="#module-sympy.core.symbol" title="Permalink to this headline">¶</a></h2>
<section id="id21">
<h3>Symbol<a class="headerlink" href="#id21" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.symbol.Symbol">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.symbol.</span></span><span class="sig-name descname"><span class="pre">Symbol</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/symbol.py#L183-L351"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.symbol.Symbol" title="Permalink to this definition">¶</a></dt>
<dd><dl class="simple">
<dt>Assumptions:</dt><dd><p>commutative = True</p>
</dd>
</dl>
<p>You can override the default assumptions in the constructor.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span><span class="n">B</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;A,B&#39;</span><span class="p">,</span> <span class="n">commutative</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">bool</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span> <span class="o">!=</span> <span class="n">B</span><span class="o">*</span><span class="n">A</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">bool</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="o">*</span><span class="mi">2</span> <span class="o">==</span> <span class="mi">2</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="p">)</span> <span class="o">==</span> <span class="kc">True</span> <span class="c1"># multiplication by scalars is commutative</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="wild">
<h3>Wild<a class="headerlink" href="#wild" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.symbol.Wild">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.symbol.</span></span><span class="sig-name descname"><span class="pre">Wild</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exclude</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">properties</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/symbol.py#L422-L543"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.symbol.Wild" title="Permalink to this definition">¶</a></dt>
<dd><p>A Wild symbol matches anything, or anything
without whatever is explicitly excluded.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>name</strong> : str</p>
<blockquote>
<div><p>Name of the Wild instance.</p>
</div></blockquote>
<p><strong>exclude</strong> : iterable, optional</p>
<blockquote>
<div><p>Instances in <code class="docutils literal notranslate"><span class="pre">exclude</span></code> will not be matched.</p>
</div></blockquote>
<p><strong>properties</strong> : iterable of functions, optional</p>
<blockquote>
<div><p>Functions, each taking an expressions as input
and returns a <code class="docutils literal notranslate"><span class="pre">bool</span></code>. All functions in <code class="docutils literal notranslate"><span class="pre">properties</span></code>
need to return <code class="docutils literal notranslate"><span class="pre">True</span></code> in order for the Wild instance
to match the expression.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Wild</span><span class="p">,</span> <span class="n">WildFunction</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">{a_: x}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">{a_: pi}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
<span class="go">{a_: 3*x}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">{a_: cos(x)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">b</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">{a_: b_}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">WildFunction</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">{a_: A_}</span>
</pre></div>
</div>
<p class="rubric">Tips</p>
<p>When using Wild, be sure to use the exclude
keyword to make the pattern more precise.
Without the exclude pattern, you may get matches
that are technically correct, but not what you
wanted. For example, using the above without
exclude:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Wild</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">y</span><span class="p">)</span>
<span class="go">{a_: 2/x, b_: 3}</span>
</pre></div>
</div>
<p>This is technically correct, because
(2/x)*x + 3*y == 2 + 3*y, but you probably
wanted it to not match at all. The issue is that
you really didn’t want a and b to include x and y,
and the exclude parameter lets you specify exactly
this.  With the exclude parameter, the pattern will
not match.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<p>Exclude also helps remove ambiguity from matches.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">E</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Wild</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">{a_: 2*y*z, b_: x**3}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">{a_: z, b_: 2*x**3*y}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">{a_: 2, b_: x**3*y*z}</span>
</pre></div>
</div>
<p>Wild also accepts a <code class="docutils literal notranslate"><span class="pre">properties</span></code> parameter:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Wild</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="p">[</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="n">k</span><span class="o">.</span><span class="n">is_Integer</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">{a_: 2, b_: x**3*y*z}</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="dummy">
<h3>Dummy<a class="headerlink" href="#dummy" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.symbol.Dummy">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.symbol.</span></span><span class="sig-name descname"><span class="pre">Dummy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dummy_index</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/symbol.py#L354-L419"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.symbol.Dummy" title="Permalink to this definition">¶</a></dt>
<dd><p>Dummy symbols are each unique, even if they have the same name:</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Dummy</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dummy</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="n">Dummy</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p>If a name is not supplied then a string value of an internal count will be
used. This is useful when a temporary variable is needed and the name
of the variable used in the expression is not important.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Dummy</span><span class="p">()</span> 
<span class="go">_Dummy_10</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="symbols">
<h3>symbols<a class="headerlink" href="#symbols" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.symbol.symbols">
<span class="sig-prename descclassname"><span class="pre">sympy.core.symbol.</span></span><span class="sig-name descname"><span class="pre">symbols</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">names</span></em>, <em class="sig-param"><span class="pre">*</span></em>, <em class="sig-param"><span class="pre">cls=&lt;class</span> <span class="pre">'sympy.core.symbol.Symbol'&gt;</span></em>, <em class="sig-param"><span class="pre">**args</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/symbol.py#L548-L757"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.symbol.symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform strings into instances of <a class="reference internal" href="#sympy.core.symbol.Symbol" title="sympy.core.symbol.Symbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Symbol</span></code></a> class.</p>
<p><a class="reference internal" href="#sympy.core.symbol.symbols" title="sympy.core.symbol.symbols"><code class="xref py py-func docutils literal notranslate"><span class="pre">symbols()</span></code></a> function returns a sequence of symbols with names taken
from <code class="docutils literal notranslate"><span class="pre">names</span></code> argument, which can be a comma or whitespace delimited
string, or a sequence of strings:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Function</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y,z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The type of output is dependent on the properties of input arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,&#39;</span><span class="p">)</span>
<span class="go">(x,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">)</span>
<span class="go">(x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">((</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">))</span>
<span class="go">(a, b, c)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">([</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="go">[a, b, c]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">({</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">})</span>
<span class="go">{a, b, c}</span>
</pre></div>
</div>
<p>If an iterable container is needed for a single symbol, set the <code class="docutils literal notranslate"><span class="pre">seq</span></code>
argument to <code class="docutils literal notranslate"><span class="pre">True</span></code> or terminate the symbol name with a comma:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">seq</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x,)</span>
</pre></div>
</div>
<p>To reduce typing, range syntax is supported to create indexed symbols.
Ranges are indicated by a colon and the type of range is determined by
the character to the right of the colon. If the character is a digit
then all contiguous digits to the left are taken as the nonnegative
starting value (or 0 if there is no digit left of the colon) and all
contiguous digits to the right are taken as 1 greater than the ending
value:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x:10&#39;</span><span class="p">)</span>
<span class="go">(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x5:10&#39;</span><span class="p">)</span>
<span class="go">(x5, x6, x7, x8, x9)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x5(:2)&#39;</span><span class="p">)</span>
<span class="go">(x50, x51)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x5:10,y:5&#39;</span><span class="p">)</span>
<span class="go">(x5, x6, x7, x8, x9, y0, y1, y2, y3, y4)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">((</span><span class="s1">&#39;x5:10&#39;</span><span class="p">,</span> <span class="s1">&#39;y:5&#39;</span><span class="p">))</span>
<span class="go">((x5, x6, x7, x8, x9), (y0, y1, y2, y3, y4))</span>
</pre></div>
</div>
<p>If the character to the right of the colon is a letter, then the single
letter to the left (or ‘a’ if there is none) is taken as the start
and all characters in the lexicographic range <em>through</em> the letter to
the right are used as the range:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x:z&#39;</span><span class="p">)</span>
<span class="go">(x, y, z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x:c&#39;</span><span class="p">)</span>  <span class="c1"># null range</span>
<span class="go">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x(:c)&#39;</span><span class="p">)</span>
<span class="go">(xa, xb, xc)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;:c&#39;</span><span class="p">)</span>
<span class="go">(a, b, c)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a:d, x:z&#39;</span><span class="p">)</span>
<span class="go">(a, b, c, d, x, y, z)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">((</span><span class="s1">&#39;a:d&#39;</span><span class="p">,</span> <span class="s1">&#39;x:z&#39;</span><span class="p">))</span>
<span class="go">((a, b, c, d), (x, y, z))</span>
</pre></div>
</div>
<p>Multiple ranges are supported; contiguous numerical ranges should be
separated by parentheses to disambiguate the ending number of one
range from the starting number of the next:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x:2(1:3)&#39;</span><span class="p">)</span>
<span class="go">(x01, x02, x11, x12)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;:3:2&#39;</span><span class="p">)</span>  <span class="c1"># parsing is from left to right</span>
<span class="go">(00, 01, 10, 11, 20, 21)</span>
</pre></div>
</div>
<p>Only one pair of parentheses surrounding ranges are removed, so to
include parentheses around ranges, double them. And to include spaces,
commas, or colons, escape them with a backslash:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x((a:b))&#39;</span><span class="p">)</span>
<span class="go">(x(a), x(b))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;x(:1\,:2)&#39;</span><span class="p">)</span>  <span class="c1"># or r&#39;x((:1)\,(:2))&#39;</span>
<span class="go">(x(0,0), x(0,1))</span>
</pre></div>
</div>
<p>All newly created symbols have assumptions set according to <code class="docutils literal notranslate"><span class="pre">args</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">is_integer</span>
<span class="go">True</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y,z&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_real</span> <span class="ow">and</span> <span class="n">y</span><span class="o">.</span><span class="n">is_real</span> <span class="ow">and</span> <span class="n">z</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Despite its name, <a class="reference internal" href="#sympy.core.symbol.symbols" title="sympy.core.symbol.symbols"><code class="xref py py-func docutils literal notranslate"><span class="pre">symbols()</span></code></a> can create symbol-like objects like
instances of Function or Wild classes. To achieve this, set <code class="docutils literal notranslate"><span class="pre">cls</span></code>
keyword argument to the desired type:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;f,g,h&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Function</span><span class="p">)</span>
<span class="go">(f, g, h)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">_</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">&lt;class &#39;sympy.core.function.UndefinedFunction&#39;&gt;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="var">
<h3>var<a class="headerlink" href="#var" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.symbol.var">
<span class="sig-prename descclassname"><span class="pre">sympy.core.symbol.</span></span><span class="sig-name descname"><span class="pre">var</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">names</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/symbol.py#L760-L821"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.symbol.var" title="Permalink to this definition">¶</a></dt>
<dd><p>Create symbols and inject them into the global namespace.</p>
<p class="rubric">Explanation</p>
<p>This calls <a class="reference internal" href="#sympy.core.symbol.symbols" title="sympy.core.symbol.symbols"><code class="xref py py-func docutils literal notranslate"><span class="pre">symbols()</span></code></a> with the same arguments and puts the results
into the <em>global</em> namespace. It’s recommended not to use <a class="reference internal" href="#sympy.core.symbol.var" title="sympy.core.symbol.var"><code class="xref py py-func docutils literal notranslate"><span class="pre">var()</span></code></a> in
library code, where <a class="reference internal" href="#sympy.core.symbol.symbols" title="sympy.core.symbol.symbols"><code class="xref py py-func docutils literal notranslate"><span class="pre">symbols()</span></code></a> has to be used:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">..</span> <span class="n">rubric</span><span class="p">::</span> <span class="n">Examples</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">var</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">var</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="c1"># noqa: F821</span>
<span class="go">x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">var</span><span class="p">(</span><span class="s1">&#39;a,ab,abc&#39;</span><span class="p">)</span>
<span class="go">(a, ab, abc)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">abc</span> <span class="c1"># noqa: F821</span>
<span class="go">abc</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">var</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">is_real</span> <span class="ow">and</span> <span class="n">y</span><span class="o">.</span><span class="n">is_real</span> <span class="c1"># noqa: F821</span>
<span class="go">True</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="#sympy.core.symbol.symbols" title="sympy.core.symbol.symbols"><code class="xref py py-func docutils literal notranslate"><span class="pre">symbols()</span></code></a> documentation for more details on what kinds of
arguments can be passed to <a class="reference internal" href="#sympy.core.symbol.var" title="sympy.core.symbol.var"><code class="xref py py-func docutils literal notranslate"><span class="pre">var()</span></code></a>.</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.numbers">
<span id="numbers"></span><h2>numbers<a class="headerlink" href="#module-sympy.core.numbers" title="Permalink to this headline">¶</a></h2>
<section id="number">
<h3>Number<a class="headerlink" href="#number" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Number">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Number</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L554-L852"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents atomic numbers in SymPy.</p>
<p class="rubric">Explanation</p>
<p>Floating point numbers are represented by the Float class.
Rational numbers (of any size) are represented by the Rational class.
Integer numbers (of any size) are represented by the Integer class.
Float and Rational are subclasses of Number; Integer is a subclass
of Rational.</p>
<p>For example, <code class="docutils literal notranslate"><span class="pre">2/3</span></code> is represented as <code class="docutils literal notranslate"><span class="pre">Rational(2,</span> <span class="pre">3)</span></code> which is
a different object from the floating point number obtained with
Python division <code class="docutils literal notranslate"><span class="pre">2/3</span></code>. Even for numbers that are exactly
represented in binary, there is a difference between how two forms,
such as <code class="docutils literal notranslate"><span class="pre">Rational(1,</span> <span class="pre">2)</span></code> and <code class="docutils literal notranslate"><span class="pre">Float(0.5)</span></code>, are used in SymPy.
The rational form is to be preferred in symbolic computations.</p>
<p>Other kinds of numbers, such as algebraic numbers <code class="docutils literal notranslate"><span class="pre">sqrt(2)</span></code> or
complex numbers <code class="docutils literal notranslate"><span class="pre">3</span> <span class="pre">+</span> <span class="pre">4*I</span></code>, are not instances of Number class as
they are not atomic.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.Float" title="sympy.core.numbers.Float"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Float</span></code></a>, <a class="reference internal" href="#sympy.core.numbers.Integer" title="sympy.core.numbers.Integer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Integer</span></code></a>, <a class="reference internal" href="#sympy.core.numbers.Rational" title="sympy.core.numbers.Rational"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Rational</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Number.as_coeff_Add">
<span class="sig-name descname"><span class="pre">as_coeff_Add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L833-L837"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number.as_coeff_Add" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a summation.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Number.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L827-L831"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a product.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Number.cofactors">
<span class="sig-name descname"><span class="pre">cofactors</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L849-L852"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number.cofactors" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute GCD and cofactors of <span class="math notranslate nohighlight">\(self\)</span> and <span class="math notranslate nohighlight">\(other\)</span>.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Number.gcd">
<span class="sig-name descname"><span class="pre">gcd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L839-L842"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number.gcd" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute GCD of <span class="math notranslate nohighlight">\(self\)</span> and <span class="math notranslate nohighlight">\(other\)</span>.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Number.lcm">
<span class="sig-name descname"><span class="pre">lcm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L844-L847"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Number.lcm" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute LCM of <span class="math notranslate nohighlight">\(self\)</span> and <span class="math notranslate nohighlight">\(other\)</span>.</p>
</dd></dl>

</dd></dl>

</section>
<section id="float">
<h3>Float<a class="headerlink" href="#float" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Float">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Float</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">num</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">precision</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L855-L1482"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Float" title="Permalink to this definition">¶</a></dt>
<dd><p>Represent a floating-point number of arbitrary precision.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Float</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mf">3.5</span><span class="p">)</span>
<span class="go">3.50000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">3.00000000000000</span>
</pre></div>
</div>
<p>Creating Floats from strings (and Python <code class="docutils literal notranslate"><span class="pre">int</span></code> and <code class="docutils literal notranslate"><span class="pre">long</span></code>
types) will give a minimum precision of 15 digits, but the
precision will automatically increase to capture all digits
entered.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">1.00000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="mi">20</span><span class="p">)</span>
<span class="go">100000000000000000000.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;1e20&#39;</span><span class="p">)</span>
<span class="go">100000000000000000000.</span>
</pre></div>
</div>
<p>However, <em>floating-point</em> numbers (Python <code class="docutils literal notranslate"><span class="pre">float</span></code> types) retain
only 15 digits of precision:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mf">1e20</span><span class="p">)</span>
<span class="go">1.00000000000000e+20</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mf">1.23456789123456789</span><span class="p">)</span>
<span class="go">1.23456789123457</span>
</pre></div>
</div>
<p>It may be preferable to enter high-precision decimal numbers
as strings:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;1.23456789123456789&#39;</span><span class="p">)</span>
<span class="go">1.23456789123456789</span>
</pre></div>
</div>
<p>The desired number of digits can also be specified:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;1e-3&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">0.00100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">100.0</span>
</pre></div>
</div>
<p>Float can automatically count significant figures if a null string
is sent for the precision; spaces or underscores are also allowed. (Auto-
counting is only allowed for strings, ints and longs).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;123 456 789.123_456&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="go">123456789.123456</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;12e-3&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="go">0.012</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="go">3.</span>
</pre></div>
</div>
<p>If a number is written in scientific notation, only the digits before the
exponent are considered significant if a decimal appears, otherwise the
“e” signifies only how to move the decimal:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;60.e2&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>  <span class="c1"># 2 digits significant</span>
<span class="go">6.0e+3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;60e2&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>  <span class="c1"># 4 digits significant</span>
<span class="go">6000.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;600e-2&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>  <span class="c1"># 3 digits significant</span>
<span class="go">6.00</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Floats are inexact by their nature unless their value is a binary-exact
value.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">approx</span><span class="p">,</span> <span class="n">exact</span> <span class="o">=</span> <span class="n">Float</span><span class="p">(</span><span class="mf">.1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">Float</span><span class="p">(</span><span class="mf">.125</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>For calculation purposes, evalf needs to be able to change the precision
but this will not increase the accuracy of the inexact value. The
following is the most accurate 5-digit approximation of a value of 0.1
that had only 1 digit of precision:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">approx</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">0.099609</span>
</pre></div>
</div>
<p>By contrast, 0.125 is exact in binary (as it is in base 10) and so it
can be passed to Float or evalf to obtain an arbitrary precision with
matching accuracy:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="n">exact</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">0.12500</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exact</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="go">0.12500000000000000000</span>
</pre></div>
</div>
<p>Trying to make a high-precision Float from a float is not disallowed,
but one must keep in mind that the <em>underlying float</em> (not the apparent
decimal value) is being obtained with high precision. For example, 0.3
does not have a finite binary representation. The closest rational is
the fraction 5404319552844595/2**54. So if you try to obtain a Float of
0.3 to 20 digits of precision you will not see the same thing as 0.3
followed by 19 zeros:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="mf">0.3</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="go">0.29999999999999998890</span>
</pre></div>
</div>
<p>If you want a 20-digit value of the decimal 0.3 (not the floating point
approximation of 0.3) you should send the 0.3 as a string. The underlying
representation is still binary but a higher precision than Python’s float
is used:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;0.3&#39;</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="go">0.30000000000000000000</span>
</pre></div>
</div>
<p>Although you can increase the precision of an existing Float using Float
it will not increase the accuracy – the underlying value is not changed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">show</span><span class="p">(</span><span class="n">f</span><span class="p">):</span> <span class="c1"># binary rep of Float</span>
<span class="gp">... </span>    <span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Mul</span><span class="p">,</span> <span class="n">Pow</span>
<span class="gp">... </span>    <span class="n">s</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">_mpf_</span>
<span class="gp">... </span>    <span class="n">v</span> <span class="o">=</span> <span class="n">Mul</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="p">),</span> <span class="n">Pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> at prec=</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">_prec</span><span class="p">))</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">Float</span><span class="p">(</span><span class="s1">&#39;0.3&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">show</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="go">4915/2**14 at prec=13</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">show</span><span class="p">(</span><span class="n">Float</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="mi">20</span><span class="p">))</span> <span class="c1"># higher prec, not higher accuracy</span>
<span class="go">4915/2**14 at prec=70</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">show</span><span class="p">(</span><span class="n">Float</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> <span class="c1"># lower prec</span>
<span class="go">307/2**10 at prec=10</span>
</pre></div>
</div>
<p>The same thing happens when evalf is used on a Float:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">show</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span>
<span class="go">4915/2**14 at prec=70</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">show</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="go">307/2**10 at prec=10</span>
</pre></div>
</div>
<p>Finally, Floats can be instantiated with an mpf tuple (n, c, p) to
produce the number (-1)**n*c*2**p:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">p</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="n">n</span><span class="o">*</span><span class="n">c</span><span class="o">*</span><span class="mi">2</span><span class="o">**</span><span class="n">p</span>
<span class="go">-5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">-5.00000000000000</span>
</pre></div>
</div>
<p>An actual mpf tuple also contains the number of bits in c as the last
element of the tuple:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">_mpf_</span>
<span class="go">(1, 5, 0, 3)</span>
</pre></div>
</div>
<p>This is not needed for instantiation and is not the same thing as the
precision. The mpf tuple and the precision are two separate quantities
that Float tracks.</p>
<p>In SymPy, a Float is a number that can be computed with arbitrary
precision. Although floating point ‘inf’ and ‘nan’ are not such
numbers, Float can create these numbers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Float</span><span class="p">(</span><span class="s1">&#39;-inf&#39;</span><span class="p">)</span>
<span class="go">-oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">is_Float</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="rational">
<h3>Rational<a class="headerlink" href="#rational" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Rational</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">q</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gcd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L1492-L2048"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents rational numbers (p/q) of any size.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">nsimplify</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">1/2</span>
</pre></div>
</div>
<p>Rational is unprejudiced in accepting input. If a float is passed, the
underlying value of the binary representation will be returned:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mf">.5</span><span class="p">)</span>
<span class="go">1/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mf">.2</span><span class="p">)</span>
<span class="go">3602879701896397/18014398509481984</span>
</pre></div>
</div>
<p>If the simpler representation of the float is desired then consider
limiting the denominator to the desired value or convert the float to
a string (which is roughly equivalent to limiting the denominator to
10**12):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="mf">.2</span><span class="p">))</span>
<span class="go">1/5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mf">.2</span><span class="p">)</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="mi">12</span><span class="p">)</span>
<span class="go">1/5</span>
</pre></div>
</div>
<p>An arbitrarily precise Rational is obtained when a string literal is
passed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s2">&quot;1.23&quot;</span><span class="p">)</span>
<span class="go">123/100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s1">&#39;1e-2&#39;</span><span class="p">)</span>
<span class="go">1/100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s2">&quot;.1&quot;</span><span class="p">)</span>
<span class="go">1/10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s1">&#39;1e-2/3.2&#39;</span><span class="p">)</span>
<span class="go">1/320</span>
</pre></div>
</div>
<p>The conversion of other types of strings can be handled by
the sympify() function, and conversion of floats to expressions
or simple fractions can be handled with nsimplify:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="s1">&#39;.[3]&#39;</span><span class="p">)</span>  <span class="c1"># repeating digits in brackets</span>
<span class="go">1/3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="s1">&#39;3**2/10&#39;</span><span class="p">)</span>  <span class="c1"># general expressions</span>
<span class="go">9/10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nsimplify</span><span class="p">(</span><span class="mf">.3</span><span class="p">)</span>  <span class="c1"># numbers that have a simple form</span>
<span class="go">3/10</span>
</pre></div>
</div>
<p>But if the input does not reduce to a literal Rational, an error will
be raised:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="n">pi</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">invalid input: pi</span>
</pre></div>
</div>
<p class="rubric">Low-level</p>
<p>Access numerator and denominator as .p and .q:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Rational</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span>
<span class="go">3/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">p</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">q</span>
<span class="go">4</span>
</pre></div>
</div>
<p>Note that p and q return integers (not SymPy Integers) so some care
is needed when using them in expressions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">p</span><span class="o">/</span><span class="n">r</span><span class="o">.</span><span class="n">q</span>
<span class="go">0.75</span>
</pre></div>
</div>
<p>If an unevaluated Rational is desired, <code class="docutils literal notranslate"><span class="pre">gcd=1</span></code> can be passed and
this will keep common divisors of the numerator and denominator
from being eliminated. It is not possible, however, to leave a
negative value in the denominator.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="n">gcd</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">2/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="n">gcd</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">q</span>
<span class="go">4</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.sympify.sympify" title="sympy.core.sympify.sympify"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.sympify.sympify</span></code></a>, <a class="reference internal" href="simplify/simplify.html#sympy.simplify.simplify.nsimplify" title="sympy.simplify.simplify.nsimplify"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.simplify.simplify.nsimplify</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational.as_coeff_Add">
<span class="sig-name descname"><span class="pre">as_coeff_Add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2046-L2048"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational.as_coeff_Add" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a summation.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2042-L2044"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a product.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2022-L2040"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (R, self/R) where R is the positive Rational
extracted from self.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(3/2, -1)</span>
</pre></div>
</div>
<p>See docstring of Expr.as_content_primitive for more examples.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational.factors">
<span class="sig-name descname"><span class="pre">factors</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_trial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_rho</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_pm1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">visual</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L1981-L1991"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational.factors" title="Permalink to this definition">¶</a></dt>
<dd><p>A wrapper to factorint which return factors of self that are
smaller than limit (or cheap to compute). Special methods of
factoring are disabled by default so that only trial division is used.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Rational.limit_denominator">
<span class="sig-name descname"><span class="pre">limit_denominator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">max_denominator</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1000000</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L1673-L1687"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Rational.limit_denominator" title="Permalink to this definition">¶</a></dt>
<dd><p>Closest Rational to self with denominator at most max_denominator.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s1">&#39;3.141592653589793&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">22/7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="s1">&#39;3.141592653589793&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="go">311/99</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="integer">
<h3>Integer<a class="headerlink" href="#integer" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Integer">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Integer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2051-L2506"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Integer" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents integer numbers of any size.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">3</span>
</pre></div>
</div>
<p>If a float or a rational is passed to Integer, the fractional part
will be discarded; the effect is of rounding toward zero.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="o">-</span><span class="mf">3.8</span><span class="p">)</span>
<span class="go">-3</span>
</pre></div>
</div>
<p>A string is acceptable input if it can be parsed as an integer:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="s2">&quot;9&quot;</span> <span class="o">*</span> <span class="mi">20</span><span class="p">)</span>
<span class="go">99999999999999999999</span>
</pre></div>
</div>
<p>It is rarely needed to explicitly instantiate an Integer, because
Python integers are automatically converted to Integer when they
are used in SymPy expressions.</p>
</dd></dl>

</section>
<section id="numbersymbol">
<h3>NumberSymbol<a class="headerlink" href="#numbersymbol" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.NumberSymbol">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">NumberSymbol</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3432-L3486"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.NumberSymbol" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.NumberSymbol.approximation">
<span class="sig-name descname"><span class="pre">approximation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number_cls</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3447-L3451"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.NumberSymbol.approximation" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an interval with number_cls endpoints
that contains the value of NumberSymbol.
If not implemented, then return None.</p>
</dd></dl>

</dd></dl>

</section>
<section id="realnumber">
<h3>RealNumber<a class="headerlink" href="#realnumber" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.numbers.RealNumber">
<span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">RealNumber</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L855-L1482"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.RealNumber" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.numbers.Float" title="sympy.core.numbers.Float"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.numbers.Float</span></code></a></p>
</dd></dl>

</section>
<section id="igcd">
<h3>igcd<a class="headerlink" href="#igcd" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.numbers.igcd">
<span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">igcd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L231-L264"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.igcd" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes nonnegative integer greatest common divisor.</p>
<p class="rubric">Explanation</p>
<p>The algorithm is based on the well known Euclid’s algorithm. To
improve speed, igcd() has its own caching mechanism implemented.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.numbers</span> <span class="kn">import</span> <span class="n">igcd</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">igcd</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">igcd</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
<span class="go">5</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="ilcm">
<h3>ilcm<a class="headerlink" href="#ilcm" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.numbers.ilcm">
<span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">ilcm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L416-L439"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.ilcm" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes integer least common multiple.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.numbers</span> <span class="kn">import</span> <span class="n">ilcm</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ilcm</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="go">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ilcm</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">21</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ilcm</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
<span class="go">30</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="seterr">
<h3>seterr<a class="headerlink" href="#seterr" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.numbers.seterr">
<span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">seterr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">divide</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L184-L193"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.seterr" title="Permalink to this definition">¶</a></dt>
<dd><p>Should sympy raise an exception on 0/0 or return a nan?</p>
<p>divide == True …. raise an exception
divide == False … return nan</p>
</dd></dl>

</section>
<section id="zero">
<h3>Zero<a class="headerlink" href="#zero" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Zero">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Zero</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2663-L2729"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Zero" title="Permalink to this definition">¶</a></dt>
<dd><p>The number zero.</p>
<p>Zero is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Zero</span></code></p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span><span class="o">/</span><span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="go">zoo</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r104"><span class="brackets"><a class="fn-backref" href="#id22">R104</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Zero">https://en.wikipedia.org/wiki/Zero</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.numbers.Zero.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2727-L2729"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Zero.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a summation.</p>
</dd></dl>

</dd></dl>

</section>
<section id="one">
<h3>One<a class="headerlink" href="#one" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.One">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">One</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2732-L2780"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.One" title="Permalink to this definition">¶</a></dt>
<dd><p>The number one.</p>
<p>One is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.One</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r105"><span class="brackets"><a class="fn-backref" href="#id23">R105</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/1_(number)">https://en.wikipedia.org/wiki/1_%28number%29</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="negativeone">
<h3>NegativeOne<a class="headerlink" href="#negativeone" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.NegativeOne">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">NegativeOne</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2783-L2844"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.NegativeOne" title="Permalink to this definition">¶</a></dt>
<dd><p>The number negative one.</p>
<p>NegativeOne is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.NegativeOne</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Integer</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">NegativeOne</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.One" title="sympy.core.numbers.One"><code class="xref py py-obj docutils literal notranslate"><span class="pre">One</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r106"><span class="brackets"><a class="fn-backref" href="#id24">R106</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/−1_(number)">https://en.wikipedia.org/wiki/%E2%88%921_%28number%29</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="half">
<h3>Half<a class="headerlink" href="#half" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Half">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Half</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2847-L2876"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Half" title="Permalink to this definition">¶</a></dt>
<dd><p>The rational number 1/2.</p>
<p>Half is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Half</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">Half</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r107"><span class="brackets"><a class="fn-backref" href="#id25">R107</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/One_half">https://en.wikipedia.org/wiki/One_half</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="nan">
<h3>NaN<a class="headerlink" href="#nan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.NaN">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">NaN</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3230-L3343"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.NaN" title="Permalink to this definition">¶</a></dt>
<dd><p>Not a Number.</p>
<p class="rubric">Explanation</p>
<p>This serves as a place holder for numeric values that are indeterminate.
Most operations on NaN, produce another NaN.  Most indeterminate forms,
such as <code class="docutils literal notranslate"><span class="pre">0/0</span></code> or <code class="docutils literal notranslate"><span class="pre">oo</span> <span class="pre">-</span> <span class="pre">oo`</span> <span class="pre">produce</span> <span class="pre">NaN.</span>&#160; <span class="pre">Two</span> <span class="pre">exceptions</span> <span class="pre">are</span> <span class="pre">``0**0</span></code>
and <code class="docutils literal notranslate"><span class="pre">oo**0</span></code>, which all produce <code class="docutils literal notranslate"><span class="pre">1</span></code> (this is consistent with Python’s
float).</p>
<p>NaN is loosely related to floating point nan, which is defined in the
IEEE 754 floating point standard, and corresponds to the Python
<code class="docutils literal notranslate"><span class="pre">float('nan')</span></code>.  Differences are noted below.</p>
<p>NaN is mathematically not equal to anything else, even NaN itself.  This
explains the initially counter-intuitive results with <code class="docutils literal notranslate"><span class="pre">Eq</span></code> and <code class="docutils literal notranslate"><span class="pre">==</span></code> in
the examples below.</p>
<p>NaN is not comparable so inequalities raise a TypeError.  This is in
contrast with floating point nan where all inequalities are false.</p>
<p>NaN is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.NaN</span></code>, or can be imported
as <code class="docutils literal notranslate"><span class="pre">nan</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">nan</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nan</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">NaN</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">oo</span> <span class="o">-</span> <span class="n">oo</span>
<span class="go">nan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nan</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">nan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">nan</span><span class="p">,</span> <span class="n">nan</span><span class="p">)</span>   <span class="c1"># mathematical equality</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nan</span> <span class="o">==</span> <span class="n">nan</span>     <span class="c1"># structural equality</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r108"><span class="brackets"><a class="fn-backref" href="#id26">R108</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/NaN">https://en.wikipedia.org/wiki/NaN</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="infinity">
<h3>Infinity<a class="headerlink" href="#infinity" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Infinity">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Infinity</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L2879-L3065"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Infinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Positive infinite quantity.</p>
<p class="rubric">Explanation</p>
<p>In real analysis the symbol <span class="math notranslate nohighlight">\(\infty\)</span> denotes an unbounded
limit: <span class="math notranslate nohighlight">\(x\to\infty\)</span> means that <span class="math notranslate nohighlight">\(x\)</span> grows without bound.</p>
<p>Infinity is often used not only to define a limit but as a value
in the affinely extended real number system.  Points labeled <span class="math notranslate nohighlight">\(+\infty\)</span>
and <span class="math notranslate nohighlight">\(-\infty\)</span> can be added to the topological space of the real numbers,
producing the two-point compactification of the real numbers.  Adding
algebraic properties to this gives us the extended real numbers.</p>
<p>Infinity is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Infinity</span></code>,
or can be imported as <code class="docutils literal notranslate"><span class="pre">oo</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">oo</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">limit</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">+</span> <span class="n">oo</span>
<span class="go">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">42</span><span class="o">/</span><span class="n">oo</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">oo</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.NegativeInfinity" title="sympy.core.numbers.NegativeInfinity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">NegativeInfinity</span></code></a>, <a class="reference internal" href="#sympy.core.numbers.NaN" title="sympy.core.numbers.NaN"><code class="xref py py-obj docutils literal notranslate"><span class="pre">NaN</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r109"><span class="brackets"><a class="fn-backref" href="#id27">R109</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Infinity">https://en.wikipedia.org/wiki/Infinity</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="negativeinfinity">
<h3>NegativeInfinity<a class="headerlink" href="#negativeinfinity" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.NegativeInfinity">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">NegativeInfinity</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3070-L3227"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.NegativeInfinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Negative infinite quantity.</p>
<p>NegativeInfinity is a singleton, and can be accessed
by <code class="docutils literal notranslate"><span class="pre">S.NegativeInfinity</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.Infinity" title="sympy.core.numbers.Infinity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Infinity</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="complexinfinity">
<h3>ComplexInfinity<a class="headerlink" href="#complexinfinity" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.ComplexInfinity">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">ComplexInfinity</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3352-L3426"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.ComplexInfinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Complex infinity.</p>
<p class="rubric">Explanation</p>
<p>In complex analysis the symbol <span class="math notranslate nohighlight">\(\tilde\infty\)</span>, called “complex
infinity”, represents a quantity with infinite magnitude, but
undetermined complex phase.</p>
<p>ComplexInfinity is a singleton, and can be accessed by
<code class="docutils literal notranslate"><span class="pre">S.ComplexInfinity</span></code>, or can be imported as <code class="docutils literal notranslate"><span class="pre">zoo</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">zoo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zoo</span> <span class="o">+</span> <span class="mi">42</span>
<span class="go">zoo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">42</span><span class="o">/</span><span class="n">zoo</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zoo</span> <span class="o">+</span> <span class="n">zoo</span>
<span class="go">nan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zoo</span><span class="o">*</span><span class="n">zoo</span>
<span class="go">zoo</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.Infinity" title="sympy.core.numbers.Infinity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Infinity</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="exp1">
<h3>Exp1<a class="headerlink" href="#exp1" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Exp1">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Exp1</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3488-L3641"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Exp1" title="Permalink to this definition">¶</a></dt>
<dd><p>The <span class="math notranslate nohighlight">\(e\)</span> constant.</p>
<p class="rubric">Explanation</p>
<p>The transcendental number <span class="math notranslate nohighlight">\(e = 2.718281828\ldots\)</span> is the base of the
natural logarithm and of the exponential function, <span class="math notranslate nohighlight">\(e = \exp(1)\)</span>.
Sometimes called Euler’s number or Napier’s constant.</p>
<p>Exp1 is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Exp1</span></code>,
or can be imported as <code class="docutils literal notranslate"><span class="pre">E</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">exp</span><span class="p">,</span> <span class="n">log</span><span class="p">,</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span> <span class="ow">is</span> <span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r110"><span class="brackets"><a class="fn-backref" href="#id28">R110</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/E_(mathematical_constant)">https://en.wikipedia.org/wiki/E_%28mathematical_constant%29</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="imaginaryunit">
<h3>ImaginaryUnit<a class="headerlink" href="#imaginaryunit" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.ImaginaryUnit">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">ImaginaryUnit</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3965-L4046"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.ImaginaryUnit" title="Permalink to this definition">¶</a></dt>
<dd><p>The imaginary unit, <span class="math notranslate nohighlight">\(i = \sqrt{-1}\)</span>.</p>
<p>I is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.I</span></code>, or can be
imported as <code class="docutils literal notranslate"><span class="pre">I</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">*</span><span class="n">I</span>
<span class="go">-1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span><span class="o">/</span><span class="n">I</span>
<span class="go">-I</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r111"><span class="brackets"><a class="fn-backref" href="#id29">R111</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Imaginary_unit">https://en.wikipedia.org/wiki/Imaginary_unit</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="pi">
<h3>Pi<a class="headerlink" href="#pi" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Pi">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Pi</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3646-L3709"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Pi" title="Permalink to this definition">¶</a></dt>
<dd><p>The <span class="math notranslate nohighlight">\(\pi\)</span> constant.</p>
<p class="rubric">Explanation</p>
<p>The transcendental number <span class="math notranslate nohighlight">\(\pi = 3.141592654\ldots\)</span> represents the ratio
of a circle’s circumference to its diameter, the area of the unit circle,
the half-period of trigonometric functions, and many other things
in mathematics.</p>
<p>Pi is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Pi</span></code>, or can
be imported as <code class="docutils literal notranslate"><span class="pre">pi</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">integrate</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">Pi</span>
<span class="go">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span> <span class="o">&gt;</span> <span class="mi">3</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pi</span><span class="o">.</span><span class="n">is_irrational</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sin</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span>
<span class="go">sin(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integrate</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="n">oo</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">sqrt(pi)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r112"><span class="brackets"><a class="fn-backref" href="#id30">R112</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Pi">https://en.wikipedia.org/wiki/Pi</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="eulergamma">
<h3>EulerGamma<a class="headerlink" href="#eulergamma" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.EulerGamma">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">EulerGamma</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3847-L3903"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.EulerGamma" title="Permalink to this definition">¶</a></dt>
<dd><p>The Euler-Mascheroni constant.</p>
<p class="rubric">Explanation</p>
<p><span class="math notranslate nohighlight">\(\gamma = 0.5772157\ldots\)</span> (also called Euler’s constant) is a mathematical
constant recurring in analysis and number theory.  It is defined as the
limiting difference between the harmonic series and the
natural logarithm:</p>
<div class="math notranslate nohighlight">
\[\gamma = \lim\limits_{n\to\infty}
\left(\sum\limits_{k=1}^n\frac{1}{k} - \ln n\right)\]</div>
<p>EulerGamma is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.EulerGamma</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">EulerGamma</span><span class="o">.</span><span class="n">is_irrational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">EulerGamma</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">EulerGamma</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r113"><span class="brackets"><a class="fn-backref" href="#id31">R113</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Euler–Mascheroni_constant">https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="catalan">
<h3>Catalan<a class="headerlink" href="#catalan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.Catalan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">Catalan</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3906-L3962"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.Catalan" title="Permalink to this definition">¶</a></dt>
<dd><p>Catalan’s constant.</p>
<p class="rubric">Explanation</p>
<p><span class="math notranslate nohighlight">\(K = 0.91596559\ldots\)</span> is given by the infinite series</p>
<div class="math notranslate nohighlight">
\[K = \sum_{k=0}^{\infty} \frac{(-1)^k}{(2k+1)^2}\]</div>
<p>Catalan is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.Catalan</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">Catalan</span><span class="o">.</span><span class="n">is_irrational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">Catalan</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">Catalan</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r114"><span class="brackets"><a class="fn-backref" href="#id32">R114</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Catalan%27s_constant">https://en.wikipedia.org/wiki/Catalan%27s_constant</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="goldenratio">
<h3>GoldenRatio<a class="headerlink" href="#goldenratio" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.GoldenRatio">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">GoldenRatio</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3714-L3774"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.GoldenRatio" title="Permalink to this definition">¶</a></dt>
<dd><p>The golden ratio, <span class="math notranslate nohighlight">\(\phi\)</span>.</p>
<p class="rubric">Explanation</p>
<p><span class="math notranslate nohighlight">\(\phi = \frac{1 + \sqrt{5}}{2}\)</span> is algebraic number.  Two quantities
are in the golden ratio if their ratio is the same as the ratio of
their sum to the larger of the two quantities, i.e. their maximum.</p>
<p>GoldenRatio is a singleton, and can be accessed by <code class="docutils literal notranslate"><span class="pre">S.GoldenRatio</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">GoldenRatio</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">GoldenRatio</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">func</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">1/2 + sqrt(5)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">GoldenRatio</span><span class="o">.</span><span class="n">is_irrational</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r115"><span class="brackets"><a class="fn-backref" href="#id33">R115</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Golden_ratio">https://en.wikipedia.org/wiki/Golden_ratio</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="tribonacciconstant">
<h3>TribonacciConstant<a class="headerlink" href="#tribonacciconstant" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.numbers.TribonacciConstant">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">TribonacciConstant</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L3777-L3844"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.TribonacciConstant" title="Permalink to this definition">¶</a></dt>
<dd><p>The tribonacci constant.</p>
<p class="rubric">Explanation</p>
<p>The tribonacci numbers are like the Fibonacci numbers, but instead
of starting with two predetermined terms, the sequence starts with
three predetermined terms and each term afterwards is the sum of the
preceding three terms.</p>
<p>The tribonacci constant is the ratio toward which adjacent tribonacci
numbers tend. It is a root of the polynomial <span class="math notranslate nohighlight">\(x^3 - x^2 - x - 1 = 0\)</span>,
and also satisfies the equation <span class="math notranslate nohighlight">\(x + x^{-3} = 2\)</span>.</p>
<p>TribonacciConstant is a singleton, and can be accessed
by <code class="docutils literal notranslate"><span class="pre">S.TribonacciConstant</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">TribonacciConstant</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">TribonacciConstant</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">func</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">1/3 + (19 - 3*sqrt(33))**(1/3)/3 + (3*sqrt(33) + 19)**(1/3)/3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">TribonacciConstant</span><span class="o">.</span><span class="n">is_irrational</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">TribonacciConstant</span><span class="o">.</span><span class="n">n</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="go">1.8392867552141611326</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r116"><span class="brackets"><a class="fn-backref" href="#id34">R116</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers">https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="mod-inverse">
<h3>mod_inverse<a class="headerlink" href="#mod-inverse" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.numbers.mod_inverse">
<span class="sig-prename descclassname"><span class="pre">sympy.core.numbers.</span></span><span class="sig-name descname"><span class="pre">mod_inverse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/numbers.py#L488-L551"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.numbers.mod_inverse" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number c such that, (a * c) = 1 (mod m)
where c has the same sign as m. If no such value exists,
a ValueError is raised.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.numbers</span> <span class="kn">import</span> <span class="n">mod_inverse</span>
</pre></div>
</div>
<p>Suppose we wish to find multiplicative inverse x of
3 modulo 11. This is the same as finding x such
that 3 * x = 1 (mod 11). One value of x that satisfies
this congruence is 4. Because 3 * 4 = 12 and 12 = 1 (mod 11).
This is the value returned by mod_inverse:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mod_inverse</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mod_inverse</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
<span class="go">7</span>
</pre></div>
</div>
<p>When there is a common factor between the numerators of
<code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">m</span></code> the inverse does not exist:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mod_inverse</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">inverse of 2 mod 4 does not exist</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mod_inverse</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">7</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="go">7/2</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r117"><span class="brackets"><a class="fn-backref" href="#id35">R117</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Modular_multiplicative_inverse">https://en.wikipedia.org/wiki/Modular_multiplicative_inverse</a></p>
</dd>
<dt class="label" id="r118"><span class="brackets"><a class="fn-backref" href="#id36">R118</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm">https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm</a></p>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.power">
<span id="power"></span><h2>power<a class="headerlink" href="#module-sympy.core.power" title="Permalink to this headline">¶</a></h2>
<section id="pow">
<h3>Pow<a class="headerlink" href="#pow" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.power.Pow">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.power.</span></span><span class="sig-name descname"><span class="pre">Pow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/power.py#L184-L1903"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.power.Pow" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines the expression x**y as “x raised to a power y”</p>
<p>Singleton definitions involving (0, 1, -1, oo, -oo, I, -I):</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 20%" />
<col style="width: 13%" />
<col style="width: 67%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>expr</p></th>
<th class="head"><p>value</p></th>
<th class="head"><p>reason</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>z**0</p></td>
<td><p>1</p></td>
<td><p>Although arguments over 0**0 exist, see [2].</p></td>
</tr>
<tr class="row-odd"><td><p>z**1</p></td>
<td><p>z</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>(-oo)**(-1)</p></td>
<td><p>0</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>(-1)**-1</p></td>
<td><p>-1</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>S.Zero**-1</p></td>
<td><p>zoo</p></td>
<td><p>This is not strictly true, as 0**-1 may be
undefined, but is convenient in some contexts
where the base is assumed to be positive.</p></td>
</tr>
<tr class="row-odd"><td><p>1**-1</p></td>
<td><p>1</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>oo**-1</p></td>
<td><p>0</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>0**oo</p></td>
<td><p>0</p></td>
<td><p>Because for all complex numbers z near
0, z**oo -&gt; 0.</p></td>
</tr>
<tr class="row-even"><td><p>0**-oo</p></td>
<td><p>zoo</p></td>
<td><p>This is not strictly true, as 0**oo may be
oscillating between positive and negative
values or rotating in the complex plane.
It is convenient, however, when the base
is positive.</p></td>
</tr>
<tr class="row-odd"><td><p>1**oo
1**-oo</p></td>
<td><p>nan</p></td>
<td><p>Because there are various cases where
lim(x(t),t)=1, lim(y(t),t)=oo (or -oo),
but lim( x(t)**y(t), t) != 1.  See [3].</p></td>
</tr>
<tr class="row-even"><td><p>b**zoo</p></td>
<td><p>nan</p></td>
<td><p>Because b**z has no limit as z -&gt; zoo</p></td>
</tr>
<tr class="row-odd"><td><p>(-1)**oo
(-1)**(-oo)</p></td>
<td><p>nan</p></td>
<td><p>Because of oscillations in the limit.</p></td>
</tr>
<tr class="row-even"><td><p>oo**oo</p></td>
<td><p>oo</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>oo**-oo</p></td>
<td><p>0</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>(-oo)**oo
(-oo)**-oo</p></td>
<td><p>nan</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p>oo**I
(-oo)**I</p></td>
<td><p>nan</p></td>
<td><p>oo**e could probably be best thought of as
the limit of x**e for real x as x tends to
oo. If e is I, then the limit does not exist
and nan is used to indicate that.</p></td>
</tr>
<tr class="row-even"><td><p>oo**(1+I)
(-oo)**(1+I)</p></td>
<td><p>zoo</p></td>
<td><p>If the real part of e is positive, then the
limit of abs(x**e) is oo. So the limit value
is zoo.</p></td>
</tr>
<tr class="row-odd"><td><p>oo**(-1+I)
-oo**(-1+I)</p></td>
<td><p>0</p></td>
<td><p>If the real part of e is negative, then the
limit is 0.</p></td>
</tr>
</tbody>
</table>
<p>Because symbolic computations are more flexible that floating point
calculations and we prefer to never return an incorrect answer,
we choose not to conform to all IEEE 754 conventions.  This helps
us avoid extra test-case code in the calculation of limits.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.numbers.Infinity" title="sympy.core.numbers.Infinity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.numbers.Infinity</span></code></a>, <a class="reference internal" href="#sympy.core.numbers.NegativeInfinity" title="sympy.core.numbers.NegativeInfinity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.numbers.NegativeInfinity</span></code></a>, <a class="reference internal" href="#sympy.core.numbers.NaN" title="sympy.core.numbers.NaN"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.numbers.NaN</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r119"><span class="brackets"><a class="fn-backref" href="#id37">R119</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Exponentiation">https://en.wikipedia.org/wiki/Exponentiation</a></p>
</dd>
<dt class="label" id="r120"><span class="brackets"><a class="fn-backref" href="#id38">R120</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero">https://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero</a></p>
</dd>
<dt class="label" id="r121"><span class="brackets"><a class="fn-backref" href="#id39">R121</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Indeterminate_forms">https://en.wikipedia.org/wiki/Indeterminate_forms</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.power.Pow.as_base_exp">
<span class="sig-name descname"><span class="pre">as_base_exp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/power.py#L925-L950"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.power.Pow.as_base_exp" title="Permalink to this definition">¶</a></dt>
<dd><p>Return base and exp of self.</p>
<p class="rubric">Explnation</p>
<p>If base is 1/Integer, then return Integer, -exp. If this extra
processing is not needed, the base and exp properties will
give the raw arguments</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Pow</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Pow</span><span class="p">(</span><span class="n">S</span><span class="o">.</span><span class="n">Half</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">as_base_exp</span><span class="p">()</span>
<span class="go">(2, -2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">args</span>
<span class="go">(1/2, 2)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.power.Pow.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/power.py#L1795-L1874"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.power.Pow.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (R, self/R) where R is the positive Rational
extracted from self.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(2, sqrt(1 + sqrt(2)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sqrt</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, sqrt(3)*sqrt(1 + sqrt(2)))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_power_base</span><span class="p">,</span> <span class="n">powsimp</span><span class="p">,</span> <span class="n">Mul</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(4, (x + 1)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">4</span><span class="o">**</span><span class="p">((</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(2, 4**(y/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">**</span><span class="p">((</span><span class="mi">1</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, 3**((y + 1)/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">**</span><span class="p">((</span><span class="mi">5</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(9, 3**((y + 1)/2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="mi">3</span><span class="o">**</span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">powsimp</span><span class="p">(</span><span class="n">eq</span><span class="p">)</span> <span class="o">==</span> <span class="n">eq</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(9, 3**(2*x))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">powsimp</span><span class="p">(</span><span class="n">Mul</span><span class="p">(</span><span class="o">*</span><span class="n">_</span><span class="p">))</span>
<span class="go">3**(2*x + 2)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">expand_power_base</span><span class="p">(</span><span class="n">eq</span><span class="p">);</span> <span class="n">s</span><span class="o">.</span><span class="n">is_Mul</span><span class="p">,</span> <span class="n">s</span>
<span class="go">(False, (2*x + 2)**y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(1, (2*(x + 1))**y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">expand_power_base</span><span class="p">(</span><span class="n">_</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span> <span class="n">s</span><span class="o">.</span><span class="n">is_Mul</span><span class="p">,</span> <span class="n">s</span>
<span class="go">(True, 2**y*(x + 1)**y)</span>
</pre></div>
</div>
<p>See docstring of Expr.as_content_primitive for more examples.</p>
</dd></dl>

</dd></dl>

</section>
<section id="integer-nthroot">
<h3>integer_nthroot<a class="headerlink" href="#integer-nthroot" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.power.integer_nthroot">
<span class="sig-prename descclassname"><span class="pre">sympy.core.power.</span></span><span class="sig-name descname"><span class="pre">integer_nthroot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/power.py#L44-L85"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.power.integer_nthroot" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing x = floor(y**(1/n))
and a boolean indicating whether the result is exact (that is,
whether x**n == y).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">integer_nthroot</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_nthroot</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">(4, True)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_nthroot</span><span class="p">(</span><span class="mi">26</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">(5, False)</span>
</pre></div>
</div>
<p>To simply determine if a number is a perfect square, the is_square
function should be used:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.ntheory.primetest</span> <span class="kn">import</span> <span class="n">is_square</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_square</span><span class="p">(</span><span class="mi">26</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="ntheory.html#sympy.ntheory.primetest.is_square" title="sympy.ntheory.primetest.is_square"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.ntheory.primetest.is_square</span></code></a>, <a class="reference internal" href="#sympy.core.power.integer_log" title="sympy.core.power.integer_log"><code class="xref py py-obj docutils literal notranslate"><span class="pre">integer_log</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="integer-log">
<h3>integer_log<a class="headerlink" href="#integer-log" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.power.integer_log">
<span class="sig-prename descclassname"><span class="pre">sympy.core.power.</span></span><span class="sig-name descname"><span class="pre">integer_log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/power.py#L129-L181"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.power.integer_log" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">(e,</span> <span class="pre">bool)</span></code> where e is the largest nonnegative integer
such that <span class="math notranslate nohighlight">\(|y| \geq |x^e|\)</span> and <code class="docutils literal notranslate"><span class="pre">bool</span></code> is True if <span class="math notranslate nohighlight">\(y = x^e\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">integer_log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_log</span><span class="p">(</span><span class="mi">125</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">(3, True)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_log</span><span class="p">(</span><span class="mi">17</span><span class="p">,</span> <span class="mi">9</span><span class="p">)</span>
<span class="go">(1, False)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_log</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">)</span>
<span class="go">(2, True)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">integer_log</span><span class="p">(</span><span class="o">-</span><span class="mi">125</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">)</span>
<span class="go">(3, True)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.power.integer_nthroot" title="sympy.core.power.integer_nthroot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">integer_nthroot</span></code></a>, <a class="reference internal" href="ntheory.html#sympy.ntheory.primetest.is_square" title="sympy.ntheory.primetest.is_square"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.ntheory.primetest.is_square</span></code></a>, <a class="reference internal" href="ntheory.html#sympy.ntheory.factor_.multiplicity" title="sympy.ntheory.factor_.multiplicity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.ntheory.factor_.multiplicity</span></code></a>, <a class="reference internal" href="ntheory.html#sympy.ntheory.factor_.perfect_power" title="sympy.ntheory.factor_.perfect_power"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.ntheory.factor_.perfect_power</span></code></a></p>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.mul">
<span id="mul"></span><h2>mul<a class="headerlink" href="#module-sympy.core.mul" title="Permalink to this headline">¶</a></h2>
<section id="id40">
<h3>Mul<a class="headerlink" href="#id40" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.mul.Mul">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.mul.</span></span><span class="sig-name descname"><span class="pre">Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_sympify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L88-L2044"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Expression representing multiplication operation for algebraic field.</p>
<p>Every argument of <code class="docutils literal notranslate"><span class="pre">Mul()</span></code> must be <code class="docutils literal notranslate"><span class="pre">Expr</span></code>. Infix operator <code class="docutils literal notranslate"><span class="pre">*</span></code>
on most scalar objects in SymPy calls this class.</p>
<p>Another use of <code class="docutils literal notranslate"><span class="pre">Mul()</span></code> is to represent the structure of abstract
multiplication so that its arguments can be substituted to return
different class. Refer to examples section for this.</p>
<p><code class="docutils literal notranslate"><span class="pre">Mul()</span></code> evaluates the argument unless <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> is passed.
The evaluation logic includes:</p>
<ol class="arabic simple">
<li><dl class="simple">
<dt>Flattening</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Mul(x,</span> <span class="pre">Mul(y,</span> <span class="pre">z))</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Mul(x,</span> <span class="pre">y,</span> <span class="pre">z)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Identity removing</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Mul(x,</span> <span class="pre">1,</span> <span class="pre">y)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Mul(x,</span> <span class="pre">y)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Exponent collecting by <code class="docutils literal notranslate"><span class="pre">.as_base_exp()</span></code></dt><dd><p><code class="docutils literal notranslate"><span class="pre">Mul(x,</span> <span class="pre">x**2)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Pow(x,</span> <span class="pre">3)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Term sorting</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Mul(y,</span> <span class="pre">x,</span> <span class="pre">2)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Mul(2,</span> <span class="pre">x,</span> <span class="pre">y)</span></code></p>
</dd>
</dl>
</li>
</ol>
<p>Since multiplication can be vector space operation, arguments may
have the different <a class="reference internal" href="#sympy.core.kind.Kind" title="sympy.core.kind.Kind"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.kind.Kind()</span></code></a>. Kind of the
resulting object is automatically inferred.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Mul</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">x**2</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> is passed, result is not evaluated.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">1*2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x*x</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Mul()</span></code> also represents the general structure of multiplication
operation.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Mul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">y</span><span class="p">:</span><span class="n">A</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span>
<span class="go">x*A</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.matrices.expressions.matmul.MatMul&#39;&gt;</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="matrices/expressions.html#sympy.matrices.expressions.MatMul" title="sympy.matrices.expressions.MatMul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatMul</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L842-L856"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a product.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.as_coefficients_dict">
<span class="sig-name descname"><span class="pre">as_coefficients_dict</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L801-L826"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.as_coefficients_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary mapping terms to their coefficient.
Since the dictionary is a defaultdict, inquiries about terms which
were not present will return a coefficient of 0. The dictionary
is considered to have a single term.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficients_dict</span><span class="p">()</span>
<span class="go">{a*x: 3}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="p">[</span><span class="n">a</span><span class="p">]</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L1999-L2023"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (R, self/R) where R is the positive Rational
extracted from self.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(6, -sqrt(2)*(1 - sqrt(2)))</span>
</pre></div>
</div>
<p>See docstring of Expr.as_content_primitive for more examples.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.as_ordered_factors">
<span class="sig-name descname"><span class="pre">as_ordered_factors</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L2025-L2040"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.as_ordered_factors" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform an expression into an ordered list of factors.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">as_ordered_factors</span><span class="p">()</span>
<span class="go">[2, x, y, sin(x), cos(x)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.as_two_terms">
<span class="sig-name descname"><span class="pre">as_two_terms</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L770-L799"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.as_two_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Return head and tail of self.</p>
<p>This is the most efficient way to get the head and tail of an
expression.</p>
<ul class="simple">
<li><p>if you want only the head, use self.args[0];</p></li>
<li><p>if you want to process the arguments of the tail then use
self.as_coef_mul() which gives the head and a tuple containing
the arguments of the tail when treated as a Mul.</p></li>
<li><p>if you want the coefficient when self is treated as an Add
then use self.as_coeff_add()[0]</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">as_two_terms</span><span class="p">()</span>
<span class="go">(3, x*y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.mul.Mul.flatten">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">seq</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L178-L704"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.Mul.flatten" title="Permalink to this definition">¶</a></dt>
<dd><p>Return commutative, noncommutative and order arguments by
combining related terms.</p>
<p class="rubric">Notes</p>
<ul>
<li><p>In an expression like <code class="docutils literal notranslate"><span class="pre">a*b*c</span></code>, python process this through sympy
as <code class="docutils literal notranslate"><span class="pre">Mul(Mul(a,</span> <span class="pre">b),</span> <span class="pre">c)</span></code>. This can have undesirable consequences.</p>
<ul class="simple">
<li><p>Sometimes terms are not combined as one would like:
{c.f. <a class="reference external" href="https://github.com/sympy/sympy/issues/4596">https://github.com/sympy/sympy/issues/4596</a>}</p></li>
</ul>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Mul</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># this is the 2-arg Mul behavior</span>
<span class="go">2*x + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span>
<span class="go">2*y*(x + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">y</span> <span class="c1"># 2-arg result will be obtained first</span>
<span class="go">y*(2*x + 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="c1"># all 3 args simultaneously processed</span>
<span class="go">2*y*(x + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="p">)</span> <span class="c1"># parentheses can control this behavior</span>
<span class="go">2*y*(x + 1)</span>
</pre></div>
</div>
<p>Powers with compound bases may not find a single base to
combine with unless all arguments are processed at once.
Post-processing may be necessary in such cases.
{c.f. <a class="reference external" href="https://github.com/sympy/sympy/issues/5728">https://github.com/sympy/sympy/issues/5728</a>}</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">**</span><span class="mi">3</span>
<span class="go">(x*sqrt(y))**(3/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">a</span><span class="p">)</span>
<span class="go">(x*sqrt(y))**(3/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">a</span>
<span class="go">x*sqrt(y)*sqrt(x*sqrt(y))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">base</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">base</span><span class="p">)</span>
<span class="go">(x*sqrt(y))**(3/2)</span>
</pre></div>
</div>
</div></blockquote>
<ul>
<li><p>If more than two terms are being multiplied then all the
previous terms will be re-processed for each new argument.
So if each of <code class="docutils literal notranslate"><span class="pre">a</span></code>, <code class="docutils literal notranslate"><span class="pre">b</span></code> and <code class="docutils literal notranslate"><span class="pre">c</span></code> were <a class="reference internal" href="#sympy.core.mul.Mul" title="sympy.core.mul.Mul"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mul</span></code></a>
expression, then <code class="docutils literal notranslate"><span class="pre">a*b*c</span></code> (or building up the product
with <code class="docutils literal notranslate"><span class="pre">*=</span></code>) will process all the arguments of <code class="docutils literal notranslate"><span class="pre">a</span></code> and
<code class="docutils literal notranslate"><span class="pre">b</span></code> twice: once when <code class="docutils literal notranslate"><span class="pre">a*b</span></code> is computed and again when
<code class="docutils literal notranslate"><span class="pre">c</span></code> is multiplied.</p>
<p>Using <code class="docutils literal notranslate"><span class="pre">Mul(a,</span> <span class="pre">b,</span> <span class="pre">c)</span></code> will process all arguments once.</p>
</li>
</ul>
</li>
<li><p>The results of Mul are cached according to arguments, so flatten
will only be called once for <code class="docutils literal notranslate"><span class="pre">Mul(a,</span> <span class="pre">b,</span> <span class="pre">c)</span></code>. If you can
structure a calculation so the arguments are most likely to be
repeats then this can save time in computing the answer. For
example, say you had a Mul, M, that you wished to divide by <code class="docutils literal notranslate"><span class="pre">d[i]</span></code>
and multiply by <code class="docutils literal notranslate"><span class="pre">n[i]</span></code> and you suspect there are many repeats
in <code class="docutils literal notranslate"><span class="pre">n</span></code>. It would be better to compute <code class="docutils literal notranslate"><span class="pre">M*n[i]/d[i]</span></code> rather
than <code class="docutils literal notranslate"><span class="pre">M/d[i]*n[i]</span></code> since every time n[i] is a repeat, the
product, <code class="docutils literal notranslate"><span class="pre">M*n[i]</span></code> will be returned without flattening – the
cached value will be returned. If you divide by the <code class="docutils literal notranslate"><span class="pre">d[i]</span></code>
first (and those are more unique than the <code class="docutils literal notranslate"><span class="pre">n[i]</span></code>) then that will
create a new Mul, <code class="docutils literal notranslate"><span class="pre">M/d[i]</span></code> the args of which will be traversed
again when it is multiplied by <code class="docutils literal notranslate"><span class="pre">n[i]</span></code>.</p>
<p>{c.f. <a class="reference external" href="https://github.com/sympy/sympy/issues/5706">https://github.com/sympy/sympy/issues/5706</a>}</p>
<p>This consideration is moot if the cache is turned off.</p>
</li>
</ul>
<p class="rubric">Nb</p>
<p>The validity of the above notes depends on the implementation
details of Mul and flatten which may change at any time. Therefore,
you should only consider them when your code is highly performance
sensitive.</p>
<p>Removal of 1 from the sequence is already handled by AssocOp.__new__.</p>
</dd></dl>

</dd></dl>

</section>
<section id="prod">
<h3>prod<a class="headerlink" href="#prod" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.mul.prod">
<span class="sig-prename descclassname"><span class="pre">sympy.core.mul.</span></span><span class="sig-name descname"><span class="pre">prod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mul.py#L2049-L2072"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mul.prod" title="Permalink to this definition">¶</a></dt>
<dd><dl class="simple">
<dt>Return product of elements of a. Start with int 1 so if only</dt><dd><p>ints are included then an int result is returned.</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">prod</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prod</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">_</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">int</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prod</span><span class="p">([</span><span class="n">S</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">is_Integer</span>
<span class="go">True</span>
</pre></div>
</div>
<p>You can start the product at something other than 1:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">prod</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">6</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.add">
<span id="add"></span><h2>add<a class="headerlink" href="#module-sympy.core.add" title="Permalink to this headline">¶</a></h2>
<section id="id41">
<h3>Add<a class="headerlink" href="#id41" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.add.Add">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.add.</span></span><span class="sig-name descname"><span class="pre">Add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_sympify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L72-L1231"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add" title="Permalink to this definition">¶</a></dt>
<dd><p>Expression representing addition operation for algebraic group.</p>
<p>Every argument of <code class="docutils literal notranslate"><span class="pre">Add()</span></code> must be <code class="docutils literal notranslate"><span class="pre">Expr</span></code>. Infix operator <code class="docutils literal notranslate"><span class="pre">+</span></code>
on most scalar objects in SymPy calls this class.</p>
<p>Another use of <code class="docutils literal notranslate"><span class="pre">Add()</span></code> is to represent the structure of abstract
addition so that its arguments can be substituted to return different
class. Refer to examples section for this.</p>
<p><code class="docutils literal notranslate"><span class="pre">Add()</span></code> evaluates the argument unless <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> is passed.
The evaluation logic includes:</p>
<ol class="arabic simple">
<li><dl class="simple">
<dt>Flattening</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Add(x,</span> <span class="pre">Add(y,</span> <span class="pre">z))</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Add(x,</span> <span class="pre">y,</span> <span class="pre">z)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Identity removing</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Add(x,</span> <span class="pre">0,</span> <span class="pre">y)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Add(x,</span> <span class="pre">y)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Coefficient collecting by <code class="docutils literal notranslate"><span class="pre">.as_coeff_Mul()</span></code></dt><dd><p><code class="docutils literal notranslate"><span class="pre">Add(x,</span> <span class="pre">2*x)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Mul(3,</span> <span class="pre">x)</span></code></p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Term sorting</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Add(y,</span> <span class="pre">x,</span> <span class="pre">2)</span></code> -&gt; <code class="docutils literal notranslate"><span class="pre">Add(2,</span> <span class="pre">x,</span> <span class="pre">y)</span></code></p>
</dd>
</dl>
</li>
</ol>
<p>If no argument is passed, identity element 0 is returned. If single
element is passed, that element is returned.</p>
<p>Note that <code class="docutils literal notranslate"><span class="pre">Add(*args)</span></code> is more efficient than <code class="docutils literal notranslate"><span class="pre">sum(args)</span></code> because
it flattens the arguments. <code class="docutils literal notranslate"><span class="pre">sum(a,</span> <span class="pre">b,</span> <span class="pre">c,</span> <span class="pre">...)</span></code> recursively adds the
arguments as <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">(b</span> <span class="pre">+</span> <span class="pre">(c</span> <span class="pre">+</span> <span class="pre">...))</span></code>, which has quadratic complexity.
On the other hand, <code class="docutils literal notranslate"><span class="pre">Add(a,</span> <span class="pre">b,</span> <span class="pre">c,</span> <span class="pre">d)</span></code> does not assume nested
structure, making the complexity linear.</p>
<p>Since addition is group operation, every argument should have the
same <a class="reference internal" href="#sympy.core.kind.Kind" title="sympy.core.kind.Kind"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.kind.Kind()</span></code></a>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Add</span><span class="p">,</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">2*x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">I</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">/</span><span class="mi">5</span> <span class="o">+</span> <span class="mf">1.0</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">2*x**2 + 17*x/5 + 3.0*y + I*y + 1</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> is passed, result is not evaluated.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">1 + 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x + x</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Add()</span></code> also represents the general structure of addition operation.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span><span class="n">A</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span><span class="n">B</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span>
<span class="go">A + B</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">&lt;class &#39;sympy.matrices.expressions.matadd.MatAdd&#39;&gt;</span>
</pre></div>
</div>
<p>Note that the printers don’t display in args order.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">args</span>
<span class="go">(1, x)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="matrices/expressions.html#sympy.matrices.expressions.MatAdd" title="sympy.matrices.expressions.MatAdd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatAdd</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_coeff_Add">
<span class="sig-name descname"><span class="pre">as_coeff_Add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L445-L453"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_coeff_Add" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a summation.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_coeff_add">
<span class="sig-name descname"><span class="pre">as_coeff_add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">deps</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L421-L443"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_coeff_add" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a tuple (coeff, args) where self is treated as an Add and coeff
is the Number term and args is a tuple of all other terms.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">7</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">()</span>
<span class="go">(7, (3*x,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">7</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coeff_add</span><span class="p">()</span>
<span class="go">(0, (7*x,))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_coefficients_dict">
<span class="sig-name descname"><span class="pre">as_coefficients_dict</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L390-L419"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_coefficients_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary mapping terms to their Rational coefficient.
Since the dictionary is a defaultdict, inquiries about terms which
were not present will return a coefficient of 0. If an expression is
not an Add it is considered to have a single term.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">a</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficients_dict</span><span class="p">()</span>
<span class="go">{1: 4, x: 3, a*x: 1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="p">[</span><span class="n">a</span><span class="p">]</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_coefficients_dict</span><span class="p">()</span>
<span class="go">{a*x: 3}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_content_primitive">
<span class="sig-name descname"><span class="pre">as_content_primitive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L1131-L1201"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_content_primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tuple (R, self/R) where R is the positive Rational
extracted from self. If radical is True (default is False) then
common radicals will be removed and included as a factor of the
primitive expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(3, 1 + sqrt(2))</span>
</pre></div>
</div>
<p>Radical content can also be factored out of the primitive:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">(</span><span class="n">radical</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(2, sqrt(2)*(1 + 2*sqrt(5)))</span>
</pre></div>
</div>
<p>See docstring of Expr.as_content_primitive for more examples.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_numer_denom">
<span class="sig-name descname"><span class="pre">as_numer_denom</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L561-L608"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_numer_denom" title="Permalink to this definition">¶</a></dt>
<dd><p>Decomposes an expression to its numerator part and its
denominator part.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">as_numer_denom</span><span class="p">()</span>
<span class="go">(x*y, z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">y</span><span class="o">**</span><span class="mi">7</span><span class="p">)</span><span class="o">.</span><span class="n">as_numer_denom</span><span class="p">()</span>
<span class="go">(x*(y + 1), y**7)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.expr.Expr.as_numer_denom" title="sympy.core.expr.Expr.as_numer_denom"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.expr.Expr.as_numer_denom</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_real_imag">
<span class="sig-name descname"><span class="pre">as_real_imag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L960-L981"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_real_imag" title="Permalink to this definition">¶</a></dt>
<dd><p>returns a tuple representing a complex number</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">7</span> <span class="o">+</span> <span class="mi">9</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">as_real_imag</span><span class="p">()</span>
<span class="go">(7, 9)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">1</span> <span class="o">+</span> <span class="n">I</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">I</span><span class="p">))</span><span class="o">.</span><span class="n">as_real_imag</span><span class="p">()</span>
<span class="go">(0, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">I</span><span class="p">))</span><span class="o">.</span><span class="n">as_real_imag</span><span class="p">()</span>
<span class="go">(-5, 5)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.as_two_terms">
<span class="sig-name descname"><span class="pre">as_two_terms</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L541-L559"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.as_two_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Return head and tail of self.</p>
<p>This is the most efficient way to get the head and tail of an
expression.</p>
<ul class="simple">
<li><p>if you want only the head, use self.args[0];</p></li>
<li><p>if you want to process the arguments of the tail then use
self.as_coef_add() which gives the head and a tuple containing
the arguments of the tail when treated as an Add.</p></li>
<li><p>if you want the coefficient when self is treated as a Mul
then use self.as_coeff_mul()[0]</p></li>
</ul>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="mi">5</span><span class="p">)</span><span class="o">.</span><span class="n">as_two_terms</span><span class="p">()</span>
<span class="go">(5, 3*x - 2*y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.class_key">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">class_key</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L372-L375"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.class_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Nice order of classes</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.extract_leading_order">
<span class="sig-name descname"><span class="pre">extract_leading_order</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">point</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L922-L958"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.extract_leading_order" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the leading term and its order.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">**</span><span class="mi">5</span><span class="p">)</span><span class="o">.</span><span class="n">extract_leading_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">((x**(-5), O(x**(-5))),)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">extract_leading_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">((1, O(1)),)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">extract_leading_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">((x, O(x)),)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.flatten">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">seq</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L159-L370"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.flatten" title="Permalink to this definition">¶</a></dt>
<dd><p>Takes the sequence “seq” of nested Adds and returns a flatten list.</p>
<p>Returns: (commutative_part, noncommutative_part, order_symbols)</p>
<p>Applies associativity, all terms are commutable with respect to
addition.</p>
<p>NB: the removal of 0 is already handled by AssocOp.__new__</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.mul.Mul.flatten" title="sympy.core.mul.Mul.flatten"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.mul.Mul.flatten</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.add.Add.primitive">
<span class="sig-name descname"><span class="pre">primitive</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/add.py#L1051-L1129"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.add.Add.primitive" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">(R,</span> <span class="pre">self/R)</span></code> where <code class="docutils literal notranslate"><span class="pre">R`</span></code> is the Rational GCD of <code class="docutils literal notranslate"><span class="pre">self`</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">R</span></code> is collected only from the leading coefficient of each term.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(2, x + 2*y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">/</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="mi">9</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(2/9, 3*x + 2*y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">/</span><span class="mi">3</span> <span class="o">+</span> <span class="mf">4.2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(1/3, 2*x + 12.6*y)</span>
</pre></div>
</div>
<p>No subprocessing of term factors is performed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">primitive</span><span class="p">()</span>
<span class="go">(1, x*(2*x + 2) + 2)</span>
</pre></div>
</div>
<p>Recursive processing can be done with the <code class="docutils literal notranslate"><span class="pre">as_content_primitive()</span></code>
method:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_content_primitive</span><span class="p">()</span>
<span class="go">(2, x*(x + 1) + 1)</span>
</pre></div>
</div>
<p>See also: primitive() function in polytools.py</p>
</dd></dl>

</dd></dl>

</section>
</section>
<section id="module-sympy.core.mod">
<span id="mod"></span><h2>mod<a class="headerlink" href="#module-sympy.core.mod" title="Permalink to this headline">¶</a></h2>
<section id="id42">
<h3>Mod<a class="headerlink" href="#id42" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.mod.Mod">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.mod.</span></span><span class="sig-name descname"><span class="pre">Mod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">p</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">q</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/mod.py#L6-L243"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.mod.Mod" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a modulo operation on symbolic expressions.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> : Expr</p>
<blockquote>
<div><p>Dividend.</p>
</div></blockquote>
<p><strong>q</strong> : Expr</p>
<blockquote>
<div><p>Divisor.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>The convention used is the same as Python’s: the remainder always has the
same sign as the divisor.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">%</span> <span class="n">y</span>
<span class="go">Mod(x**2, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">6</span><span class="p">})</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.relational">
<span id="relational"></span><h2>relational<a class="headerlink" href="#module-sympy.core.relational" title="Permalink to this headline">¶</a></h2>
<section id="rel">
<h3>Rel<a class="headerlink" href="#rel" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.Relational">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Relational</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L44-L418"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Relational" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for all relation types.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rop</strong> : str or None</p>
<blockquote>
<div><p>Indicates what subclass to instantiate.  Valid values can be found
in the keys of Relational.ValidRelationOperator.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Subclasses of Relational should generally be instantiated directly, but
Relational can be instantiated with a valid <code class="docutils literal notranslate"><span class="pre">rop</span></code> value to dispatch to
the appropriate subclass.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rel</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Rel</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;==&#39;</span><span class="p">)</span>
<span class="go">Eq(y, x**2 + x)</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.canonical">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">canonical</span></span><a class="headerlink" href="#sympy.core.relational.Relational.canonical" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a canonical form of the relational by putting a
number on the rhs, canonically removing a sign or else
ordering the args canonically. No other simplification is
attempted.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">2</span>
<span class="go">x &lt; 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">reversed</span><span class="o">.</span><span class="n">canonical</span>
<span class="go">x &lt; 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">canonical</span>
<span class="go">x &gt; -y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">y</span> <span class="o">&gt;</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">canonical</span>
<span class="go">x &lt; -y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">y</span> <span class="o">&lt;</span> <span class="o">-</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">canonical</span>
<span class="go">x &lt; y</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.equals">
<span class="sig-name descname"><span class="pre">equals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">failing_expression</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L255-L301"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Relational.equals" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the sides of the relationship are mathematically
identical and the type of relationship is the same.
If failing_expression is True, return the expression whose truth value
was unknown.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.lhs">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">lhs</span></span><a class="headerlink" href="#sympy.core.relational.Relational.lhs" title="Permalink to this definition">¶</a></dt>
<dd><p>The left-hand side of the relation.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.negated">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">negated</span></span><a class="headerlink" href="#sympy.core.relational.Relational.negated" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the negated relationship.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Eq(x, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">negated</span>
<span class="go">Ne(x, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">negated</span>
<span class="go">x &gt;= 1</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This works more or less identical to <code class="docutils literal notranslate"><span class="pre">~</span></code>/<code class="docutils literal notranslate"><span class="pre">Not</span></code>. The difference is
that <code class="docutils literal notranslate"><span class="pre">negated</span></code> returns the relationship even if <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code>.
Hence, this is useful in code when checking for e.g. negated relations
to existing ones as it will not be affected by the <span class="math notranslate nohighlight">\(evaluate\)</span> flag.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.reversed">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">reversed</span></span><a class="headerlink" href="#sympy.core.relational.Relational.reversed" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the relationship with sides reversed.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Eq(x, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">reversed</span>
<span class="go">Eq(1, x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">reversed</span>
<span class="go">1 &gt; x</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.reversedsign">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">reversedsign</span></span><a class="headerlink" href="#sympy.core.relational.Relational.reversedsign" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the relationship with signs reversed.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Eq(x, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">reversedsign</span>
<span class="go">Eq(-x, -1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">reversedsign</span>
<span class="go">-x &gt; -1</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.relational.Relational.rhs">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">rhs</span></span><a class="headerlink" href="#sympy.core.relational.Relational.rhs" title="Permalink to this definition">¶</a></dt>
<dd><p>The right-hand side of the relation.</p>
</dd></dl>

</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Rel">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Rel</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L44-L418"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Rel" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.Relational" title="sympy.core.relational.Relational"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.Relational</span></code></a></p>
</dd></dl>

</section>
<section id="eq">
<h3>Eq<a class="headerlink" href="#eq" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Eq">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Eq</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L424-L604"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Eq" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.Equality" title="sympy.core.relational.Equality"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.Equality</span></code></a></p>
</dd></dl>

</section>
<section id="ne">
<h3>Ne<a class="headerlink" href="#ne" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Ne">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Ne</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L610-L679"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Ne" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.Unequality" title="sympy.core.relational.Unequality"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.Unequality</span></code></a></p>
</dd></dl>

</section>
<section id="lt">
<h3>Lt<a class="headerlink" href="#lt" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Lt">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Lt</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1032-L1040"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Lt" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.StrictLessThan" title="sympy.core.relational.StrictLessThan"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.StrictLessThan</span></code></a></p>
</dd></dl>

</section>
<section id="le">
<h3>Le<a class="headerlink" href="#le" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Le">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Le</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1004-L1012"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Le" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.LessThan" title="sympy.core.relational.LessThan"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.LessThan</span></code></a></p>
</dd></dl>

</section>
<section id="gt">
<h3>Gt<a class="headerlink" href="#gt" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Gt">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Gt</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1018-L1026"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Gt" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.StrictGreaterThan" title="sympy.core.relational.StrictGreaterThan"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.StrictGreaterThan</span></code></a></p>
</dd></dl>

</section>
<section id="ge">
<h3>Ge<a class="headerlink" href="#ge" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.relational.Ge">
<span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Ge</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L767-L998"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Ge" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#sympy.core.relational.GreaterThan" title="sympy.core.relational.GreaterThan"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.relational.GreaterThan</span></code></a></p>
</dd></dl>

</section>
<section id="equality">
<h3>Equality<a class="headerlink" href="#equality" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.Equality">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Equality</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L424-L604"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Equality" title="Permalink to this definition">¶</a></dt>
<dd><p>An equal relation between two objects.</p>
<p class="rubric">Explanation</p>
<p>Represents that two objects are equal.  If they can be easily shown
to be definitively equal (or unequal), this will reduce to True (or
False).  Otherwise, the relation is maintained as an unevaluated
Equality object.  Use the <code class="docutils literal notranslate"><span class="pre">simplify</span></code> function on this object for
more nontrivial evaluation of the equality relation.</p>
<p>As usual, the keyword argument <code class="docutils literal notranslate"><span class="pre">evaluate=False</span></code> can be used to
prevent any evaluation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">Eq(y, x**2 + x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">Eq(2, 5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">cos</span><span class="p">))</span>
<span class="go">Eq(exp(x), sinh(x) + cosh(x))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Python treats 1 and True (and 0 and False) as being equal; SymPy
does not. And integer will always compare as unequal to a Boolean:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="kc">True</span> <span class="o">==</span> <span class="mi">1</span>
<span class="go">(False, True)</span>
</pre></div>
</div>
<p>This class is not the same as the == operator.  The == operator tests
for exact structural equality between two expressions; this class
compares expressions mathematically.</p>
<p>If either object defines an <code class="docutils literal notranslate"><span class="pre">_eval_Eq</span></code> method, it can be used in place of
the default algorithm.  If <code class="docutils literal notranslate"><span class="pre">lhs._eval_Eq(rhs)</span></code> or <code class="docutils literal notranslate"><span class="pre">rhs._eval_Eq(lhs)</span></code>
returns anything other than None, that return value will be substituted for
the Equality.  If None is returned by <code class="docutils literal notranslate"><span class="pre">_eval_Eq</span></code>, an Equality object will
be created as usual.</p>
<p>Since this object is already an expression, it does not respond to
the method <code class="docutils literal notranslate"><span class="pre">as_expr</span></code> if one tries to create <span class="math notranslate nohighlight">\(x - y\)</span> from <code class="docutils literal notranslate"><span class="pre">Eq(x,</span> <span class="pre">y)</span></code>.
This can be done with the <code class="docutils literal notranslate"><span class="pre">rewrite(Add)</span></code> method.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="logic.html#sympy.logic.boolalg.Equivalent" title="sympy.logic.boolalg.Equivalent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.logic.boolalg.Equivalent</span></code></a></dt><dd><p>for representing equality between two boolean expressions</p>
</dd>
</dl>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.relational.Equality.as_poly">
<span class="sig-name descname"><span class="pre">as_poly</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L593-L604"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Equality.as_poly" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns lhs-rhs as a Poly</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">as_poly</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Poly(x**2 - 1, x, domain=&#39;ZZ&#39;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.relational.Equality.integrate">
<span class="sig-name descname"><span class="pre">integrate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L588-L591"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Equality.integrate" title="Permalink to this definition">¶</a></dt>
<dd><p>See the integrate function in sympy.integrals</p>
</dd></dl>

</dd></dl>

</section>
<section id="greaterthan">
<h3>GreaterThan<a class="headerlink" href="#greaterthan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.GreaterThan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">GreaterThan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L767-L998"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.GreaterThan" title="Permalink to this definition">¶</a></dt>
<dd><p>Class representations of inequalities.</p>
<p class="rubric">Explanation</p>
<p>The <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes represent inequal relationships, where the left-hand
side is generally bigger or smaller than the right-hand side.  For example,
the GreaterThan class represents an inequal relationship where the
left-hand side is at least as big as the right side, if not bigger.  In
mathematical notation:</p>
<p>lhs &gt;= rhs</p>
<p>In total, there are four <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes, to represent the four
inequalities:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 68%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Class Name</p></th>
<th class="head"><p>Symbol</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan</p></td>
<td><p>(&gt;=)</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan</p></td>
<td><p>(&lt;=)</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan</p></td>
<td><p>(&gt;)</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan</p></td>
<td><p>(&lt;)</p></td>
</tr>
</tbody>
</table>
<p>All classes take two arguments, lhs and rhs.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 62%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Signature Example</p></th>
<th class="head"><p>Math equivalent</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;= rhs</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;= rhs</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;  rhs</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;  rhs</p></td>
</tr>
</tbody>
</table>
<p>In addition to the normal .lhs and .rhs of Relations, <code class="docutils literal notranslate"><span class="pre">*Than</span></code> inequality
objects also have the .lts and .gts properties, which represent the “less
than side” and “greater than side” of the operator.  Use of .lts and .gts
in an algorithm rather than .lhs and .rhs as an assumption of inequality
direction will make more explicit the intent of a certain section of code,
and will make it similarly more robust to client code changes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">GreaterThan</span><span class="p">,</span> <span class="n">StrictGreaterThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">LessThan</span><span class="p">,</span>    <span class="n">StrictLessThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">And</span><span class="p">,</span> <span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">,</span> <span class="n">Rel</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.relational</span> <span class="kn">import</span> <span class="n">Relational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> &gt;= </span><span class="si">%s</span><span class="s1"> is the same as </span><span class="si">%s</span><span class="s1"> &lt;= </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">)</span>
<span class="go">&#39;x &gt;= 1 is the same as 1 &lt;= x&#39;</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<p>One generally does not instantiate these classes directly, but uses various
convenience methods:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">]:</span>  <span class="c1"># convenience wrappers</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x &gt;= 2</span>
<span class="go">x &gt; 2</span>
<span class="go">x &lt;= 2</span>
<span class="go">x &lt; 2</span>
</pre></div>
</div>
<p>Another option is to use the Python inequality operators (&gt;=, &gt;, &lt;=, &lt;)
directly.  Their main advantage over the Ge, Gt, Le, and Lt counterparts,
is that one can write a more “mathematical looking” statement rather than
littering the math with oddball function calls.  However there are certain
(minor) caveats of which to be aware (search for ‘gotcha’, below).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">2</span>
<span class="go">x &gt;= 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">==</span> <span class="n">Ge</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>However, it is also perfectly valid to instantiate a <code class="docutils literal notranslate"><span class="pre">*Than</span></code> class less
succinctly and less conveniently:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rel</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">StrictGreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">LessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">StrictLessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt; 1</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>There are a couple of “gotchas” to be aware of when using Python’s
operators.</p>
<p>The first is that what your write is not always what you get:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<p>Due to the order that Python parses a statement, it may
not immediately find two objects comparable.  When “1 &lt; x”
is evaluated, Python recognizes that the number 1 is a native
number and that x is <em>not</em>.  Because a native Python number does
not know how to compare itself with a SymPy object
Python will try the reflective operation, “x &gt; 1” and that is the
form that gets evaluated, hence returned.</p>
<p>If the order of the statement is important (for visual output to
the console, perhaps), one can work around this annoyance in a
couple ways:</p>
<ol class="arabic simple">
<li><p>“sympify” the literal before comparison</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
<p>(2) use one of the wrappers or less succinct methods described
above</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Lt</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="s2">&quot;&lt;&quot;</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
</div></blockquote>
<p>The second gotcha involves writing equality tests between relationals
when one or both sides of the test involve a literal relational:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">;</span> <span class="n">e</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">e</span>  <span class="c1"># neither side is a literal</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting True, too</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False or the same thing as before</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
<p>The solution for this case is to wrap literal relationals in
parentheses:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</div></blockquote>
<p>The third gotcha involves chained inequalities not involving
‘==’ or ‘!=’. Occasionally, one may be tempted to write:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">symbolic boolean expression has no truth value.</span>
</pre></div>
</div>
<p>Due to an implementation detail or decision of Python <a class="reference internal" href="#r122" id="id43"><span>[R122]</span></a>,
there is no way for SymPy to create a chained inequality with
that syntax so one must use And:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span> <span class="n">e</span> <span class="p">)</span>
<span class="go">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
</pre></div>
</div>
<p>Although this can also be done with the ‘&amp;’ operator, it cannot
be done with the ‘and’ operarator:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
</div></blockquote>
<dl class="citation">
<dt class="label" id="r122"><span class="brackets"><a class="fn-backref" href="#id43">R122</a></span></dt>
<dd><p>This implementation detail is that Python provides no reliable
method to determine that a chained inequality is being built.
Chained comparison operators are evaluated pairwise, using “and”
logic (see
<a class="reference external" href="http://docs.python.org/reference/expressions.html#not-in">http://docs.python.org/reference/expressions.html#not-in</a>). This
is done in an efficient way, so that each object being compared
is only evaluated once and the comparison can short-circuit. For
example, <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">&gt;</span> <span class="pre">2</span> <span class="pre">&gt;</span> <span class="pre">3</span></code> is evaluated by Python as <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">&gt;</span> <span class="pre">2)</span> <span class="pre">and</span> <span class="pre">(2</span>
<span class="pre">&gt;</span> <span class="pre">3)</span></code>. The <code class="docutils literal notranslate"><span class="pre">and</span></code> operator coerces each side into a bool,
returning the object itself when it short-circuits. The bool of
the –Than operators will raise TypeError on purpose, because
SymPy cannot determine the mathematical ordering of symbolic
expressions. Thus, if we were to compute <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code>, with
<code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">y</span></code>, and <code class="docutils literal notranslate"><span class="pre">z</span></code> being Symbols, Python converts the
statement (roughly) into these steps:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>x &gt; y &gt; z</p></li>
<li><p>(x &gt; y) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject.__bool__()) and (y &gt; z)</p></li>
<li><p>TypeError</p></li>
</ol>
</div></blockquote>
<p>Because of the “and” added at step 2, the statement gets turned into a
weak ternary statement, and the first object’s __bool__ method will
raise TypeError.  Thus, creating a chained inequality is not possible.</p>
<blockquote>
<div><p>In Python, there is no way to override the <code class="docutils literal notranslate"><span class="pre">and</span></code> operator, or to
control how it short circuits, so it is impossible to make something
like <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code> work.  There was a PEP to change this,
<span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0335"><strong>PEP 335</strong></a>, but it was officially closed in March, 2012.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
<section id="lessthan">
<h3>LessThan<a class="headerlink" href="#lessthan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.LessThan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">LessThan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1004-L1012"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.LessThan" title="Permalink to this definition">¶</a></dt>
<dd><p>Class representations of inequalities.</p>
<p class="rubric">Explanation</p>
<p>The <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes represent inequal relationships, where the left-hand
side is generally bigger or smaller than the right-hand side.  For example,
the GreaterThan class represents an inequal relationship where the
left-hand side is at least as big as the right side, if not bigger.  In
mathematical notation:</p>
<p>lhs &gt;= rhs</p>
<p>In total, there are four <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes, to represent the four
inequalities:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 68%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Class Name</p></th>
<th class="head"><p>Symbol</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan</p></td>
<td><p>(&gt;=)</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan</p></td>
<td><p>(&lt;=)</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan</p></td>
<td><p>(&gt;)</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan</p></td>
<td><p>(&lt;)</p></td>
</tr>
</tbody>
</table>
<p>All classes take two arguments, lhs and rhs.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 62%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Signature Example</p></th>
<th class="head"><p>Math equivalent</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;= rhs</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;= rhs</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;  rhs</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;  rhs</p></td>
</tr>
</tbody>
</table>
<p>In addition to the normal .lhs and .rhs of Relations, <code class="docutils literal notranslate"><span class="pre">*Than</span></code> inequality
objects also have the .lts and .gts properties, which represent the “less
than side” and “greater than side” of the operator.  Use of .lts and .gts
in an algorithm rather than .lhs and .rhs as an assumption of inequality
direction will make more explicit the intent of a certain section of code,
and will make it similarly more robust to client code changes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">GreaterThan</span><span class="p">,</span> <span class="n">StrictGreaterThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">LessThan</span><span class="p">,</span>    <span class="n">StrictLessThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">And</span><span class="p">,</span> <span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">,</span> <span class="n">Rel</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.relational</span> <span class="kn">import</span> <span class="n">Relational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> &gt;= </span><span class="si">%s</span><span class="s1"> is the same as </span><span class="si">%s</span><span class="s1"> &lt;= </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">)</span>
<span class="go">&#39;x &gt;= 1 is the same as 1 &lt;= x&#39;</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<p>One generally does not instantiate these classes directly, but uses various
convenience methods:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">]:</span>  <span class="c1"># convenience wrappers</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x &gt;= 2</span>
<span class="go">x &gt; 2</span>
<span class="go">x &lt;= 2</span>
<span class="go">x &lt; 2</span>
</pre></div>
</div>
<p>Another option is to use the Python inequality operators (&gt;=, &gt;, &lt;=, &lt;)
directly.  Their main advantage over the Ge, Gt, Le, and Lt counterparts,
is that one can write a more “mathematical looking” statement rather than
littering the math with oddball function calls.  However there are certain
(minor) caveats of which to be aware (search for ‘gotcha’, below).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">2</span>
<span class="go">x &gt;= 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">==</span> <span class="n">Ge</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>However, it is also perfectly valid to instantiate a <code class="docutils literal notranslate"><span class="pre">*Than</span></code> class less
succinctly and less conveniently:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rel</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">StrictGreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">LessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">StrictLessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt; 1</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>There are a couple of “gotchas” to be aware of when using Python’s
operators.</p>
<p>The first is that what your write is not always what you get:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<p>Due to the order that Python parses a statement, it may
not immediately find two objects comparable.  When “1 &lt; x”
is evaluated, Python recognizes that the number 1 is a native
number and that x is <em>not</em>.  Because a native Python number does
not know how to compare itself with a SymPy object
Python will try the reflective operation, “x &gt; 1” and that is the
form that gets evaluated, hence returned.</p>
<p>If the order of the statement is important (for visual output to
the console, perhaps), one can work around this annoyance in a
couple ways:</p>
<ol class="arabic simple">
<li><p>“sympify” the literal before comparison</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
<p>(2) use one of the wrappers or less succinct methods described
above</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Lt</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="s2">&quot;&lt;&quot;</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
</div></blockquote>
<p>The second gotcha involves writing equality tests between relationals
when one or both sides of the test involve a literal relational:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">;</span> <span class="n">e</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">e</span>  <span class="c1"># neither side is a literal</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting True, too</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False or the same thing as before</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
<p>The solution for this case is to wrap literal relationals in
parentheses:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</div></blockquote>
<p>The third gotcha involves chained inequalities not involving
‘==’ or ‘!=’. Occasionally, one may be tempted to write:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">symbolic boolean expression has no truth value.</span>
</pre></div>
</div>
<p>Due to an implementation detail or decision of Python <a class="reference internal" href="#r123" id="id44"><span>[R123]</span></a>,
there is no way for SymPy to create a chained inequality with
that syntax so one must use And:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span> <span class="n">e</span> <span class="p">)</span>
<span class="go">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
</pre></div>
</div>
<p>Although this can also be done with the ‘&amp;’ operator, it cannot
be done with the ‘and’ operarator:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
</div></blockquote>
<dl class="citation">
<dt class="label" id="r123"><span class="brackets"><a class="fn-backref" href="#id44">R123</a></span></dt>
<dd><p>This implementation detail is that Python provides no reliable
method to determine that a chained inequality is being built.
Chained comparison operators are evaluated pairwise, using “and”
logic (see
<a class="reference external" href="http://docs.python.org/reference/expressions.html#not-in">http://docs.python.org/reference/expressions.html#not-in</a>). This
is done in an efficient way, so that each object being compared
is only evaluated once and the comparison can short-circuit. For
example, <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">&gt;</span> <span class="pre">2</span> <span class="pre">&gt;</span> <span class="pre">3</span></code> is evaluated by Python as <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">&gt;</span> <span class="pre">2)</span> <span class="pre">and</span> <span class="pre">(2</span>
<span class="pre">&gt;</span> <span class="pre">3)</span></code>. The <code class="docutils literal notranslate"><span class="pre">and</span></code> operator coerces each side into a bool,
returning the object itself when it short-circuits. The bool of
the –Than operators will raise TypeError on purpose, because
SymPy cannot determine the mathematical ordering of symbolic
expressions. Thus, if we were to compute <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code>, with
<code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">y</span></code>, and <code class="docutils literal notranslate"><span class="pre">z</span></code> being Symbols, Python converts the
statement (roughly) into these steps:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>x &gt; y &gt; z</p></li>
<li><p>(x &gt; y) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject.__bool__()) and (y &gt; z)</p></li>
<li><p>TypeError</p></li>
</ol>
</div></blockquote>
<p>Because of the “and” added at step 2, the statement gets turned into a
weak ternary statement, and the first object’s __bool__ method will
raise TypeError.  Thus, creating a chained inequality is not possible.</p>
<blockquote>
<div><p>In Python, there is no way to override the <code class="docutils literal notranslate"><span class="pre">and</span></code> operator, or to
control how it short circuits, so it is impossible to make something
like <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code> work.  There was a PEP to change this,
<span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0335"><strong>PEP 335</strong></a>, but it was officially closed in March, 2012.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
<section id="unequality">
<h3>Unequality<a class="headerlink" href="#unequality" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.Unequality">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">Unequality</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L610-L679"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.Unequality" title="Permalink to this definition">¶</a></dt>
<dd><p>An unequal relation between two objects.</p>
<p class="rubric">Explanation</p>
<p>Represents that two objects are not equal.  If they can be shown to be
definitively equal, this will reduce to False; if definitively unequal,
this will reduce to True.  Otherwise, the relation is maintained as an
Unequality object.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Ne</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Ne</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">Ne(y, x**2 + x)</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This class is not the same as the != operator.  The != operator tests
for exact structural equality between two expressions; this class
compares expressions mathematically.</p>
<p>This class is effectively the inverse of Equality.  As such, it uses the
same algorithms, including any available <span class="math notranslate nohighlight">\(_eval_Eq\)</span> methods.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.relational.Equality" title="sympy.core.relational.Equality"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Equality</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="strictgreaterthan">
<h3>StrictGreaterThan<a class="headerlink" href="#strictgreaterthan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.StrictGreaterThan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">StrictGreaterThan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1018-L1026"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.StrictGreaterThan" title="Permalink to this definition">¶</a></dt>
<dd><p>Class representations of inequalities.</p>
<p class="rubric">Explanation</p>
<p>The <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes represent inequal relationships, where the left-hand
side is generally bigger or smaller than the right-hand side.  For example,
the GreaterThan class represents an inequal relationship where the
left-hand side is at least as big as the right side, if not bigger.  In
mathematical notation:</p>
<p>lhs &gt;= rhs</p>
<p>In total, there are four <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes, to represent the four
inequalities:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 68%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Class Name</p></th>
<th class="head"><p>Symbol</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan</p></td>
<td><p>(&gt;=)</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan</p></td>
<td><p>(&lt;=)</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan</p></td>
<td><p>(&gt;)</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan</p></td>
<td><p>(&lt;)</p></td>
</tr>
</tbody>
</table>
<p>All classes take two arguments, lhs and rhs.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 62%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Signature Example</p></th>
<th class="head"><p>Math equivalent</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;= rhs</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;= rhs</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;  rhs</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;  rhs</p></td>
</tr>
</tbody>
</table>
<p>In addition to the normal .lhs and .rhs of Relations, <code class="docutils literal notranslate"><span class="pre">*Than</span></code> inequality
objects also have the .lts and .gts properties, which represent the “less
than side” and “greater than side” of the operator.  Use of .lts and .gts
in an algorithm rather than .lhs and .rhs as an assumption of inequality
direction will make more explicit the intent of a certain section of code,
and will make it similarly more robust to client code changes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">GreaterThan</span><span class="p">,</span> <span class="n">StrictGreaterThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">LessThan</span><span class="p">,</span>    <span class="n">StrictLessThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">And</span><span class="p">,</span> <span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">,</span> <span class="n">Rel</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.relational</span> <span class="kn">import</span> <span class="n">Relational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> &gt;= </span><span class="si">%s</span><span class="s1"> is the same as </span><span class="si">%s</span><span class="s1"> &lt;= </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">)</span>
<span class="go">&#39;x &gt;= 1 is the same as 1 &lt;= x&#39;</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<p>One generally does not instantiate these classes directly, but uses various
convenience methods:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">]:</span>  <span class="c1"># convenience wrappers</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x &gt;= 2</span>
<span class="go">x &gt; 2</span>
<span class="go">x &lt;= 2</span>
<span class="go">x &lt; 2</span>
</pre></div>
</div>
<p>Another option is to use the Python inequality operators (&gt;=, &gt;, &lt;=, &lt;)
directly.  Their main advantage over the Ge, Gt, Le, and Lt counterparts,
is that one can write a more “mathematical looking” statement rather than
littering the math with oddball function calls.  However there are certain
(minor) caveats of which to be aware (search for ‘gotcha’, below).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">2</span>
<span class="go">x &gt;= 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">==</span> <span class="n">Ge</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>However, it is also perfectly valid to instantiate a <code class="docutils literal notranslate"><span class="pre">*Than</span></code> class less
succinctly and less conveniently:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rel</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">StrictGreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">LessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">StrictLessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt; 1</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>There are a couple of “gotchas” to be aware of when using Python’s
operators.</p>
<p>The first is that what your write is not always what you get:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<p>Due to the order that Python parses a statement, it may
not immediately find two objects comparable.  When “1 &lt; x”
is evaluated, Python recognizes that the number 1 is a native
number and that x is <em>not</em>.  Because a native Python number does
not know how to compare itself with a SymPy object
Python will try the reflective operation, “x &gt; 1” and that is the
form that gets evaluated, hence returned.</p>
<p>If the order of the statement is important (for visual output to
the console, perhaps), one can work around this annoyance in a
couple ways:</p>
<ol class="arabic simple">
<li><p>“sympify” the literal before comparison</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
<p>(2) use one of the wrappers or less succinct methods described
above</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Lt</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="s2">&quot;&lt;&quot;</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
</div></blockquote>
<p>The second gotcha involves writing equality tests between relationals
when one or both sides of the test involve a literal relational:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">;</span> <span class="n">e</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">e</span>  <span class="c1"># neither side is a literal</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting True, too</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False or the same thing as before</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
<p>The solution for this case is to wrap literal relationals in
parentheses:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</div></blockquote>
<p>The third gotcha involves chained inequalities not involving
‘==’ or ‘!=’. Occasionally, one may be tempted to write:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">symbolic boolean expression has no truth value.</span>
</pre></div>
</div>
<p>Due to an implementation detail or decision of Python <a class="reference internal" href="#r124" id="id45"><span>[R124]</span></a>,
there is no way for SymPy to create a chained inequality with
that syntax so one must use And:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span> <span class="n">e</span> <span class="p">)</span>
<span class="go">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
</pre></div>
</div>
<p>Although this can also be done with the ‘&amp;’ operator, it cannot
be done with the ‘and’ operarator:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
</div></blockquote>
<dl class="citation">
<dt class="label" id="r124"><span class="brackets"><a class="fn-backref" href="#id45">R124</a></span></dt>
<dd><p>This implementation detail is that Python provides no reliable
method to determine that a chained inequality is being built.
Chained comparison operators are evaluated pairwise, using “and”
logic (see
<a class="reference external" href="http://docs.python.org/reference/expressions.html#not-in">http://docs.python.org/reference/expressions.html#not-in</a>). This
is done in an efficient way, so that each object being compared
is only evaluated once and the comparison can short-circuit. For
example, <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">&gt;</span> <span class="pre">2</span> <span class="pre">&gt;</span> <span class="pre">3</span></code> is evaluated by Python as <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">&gt;</span> <span class="pre">2)</span> <span class="pre">and</span> <span class="pre">(2</span>
<span class="pre">&gt;</span> <span class="pre">3)</span></code>. The <code class="docutils literal notranslate"><span class="pre">and</span></code> operator coerces each side into a bool,
returning the object itself when it short-circuits. The bool of
the –Than operators will raise TypeError on purpose, because
SymPy cannot determine the mathematical ordering of symbolic
expressions. Thus, if we were to compute <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code>, with
<code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">y</span></code>, and <code class="docutils literal notranslate"><span class="pre">z</span></code> being Symbols, Python converts the
statement (roughly) into these steps:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>x &gt; y &gt; z</p></li>
<li><p>(x &gt; y) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject.__bool__()) and (y &gt; z)</p></li>
<li><p>TypeError</p></li>
</ol>
</div></blockquote>
<p>Because of the “and” added at step 2, the statement gets turned into a
weak ternary statement, and the first object’s __bool__ method will
raise TypeError.  Thus, creating a chained inequality is not possible.</p>
<blockquote>
<div><p>In Python, there is no way to override the <code class="docutils literal notranslate"><span class="pre">and</span></code> operator, or to
control how it short circuits, so it is impossible to make something
like <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code> work.  There was a PEP to change this,
<span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0335"><strong>PEP 335</strong></a>, but it was officially closed in March, 2012.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
<section id="strictlessthan">
<h3>StrictLessThan<a class="headerlink" href="#strictlessthan" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.relational.StrictLessThan">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.relational.</span></span><span class="sig-name descname"><span class="pre">StrictLessThan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rhs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/relational.py#L1032-L1040"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.relational.StrictLessThan" title="Permalink to this definition">¶</a></dt>
<dd><p>Class representations of inequalities.</p>
<p class="rubric">Explanation</p>
<p>The <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes represent inequal relationships, where the left-hand
side is generally bigger or smaller than the right-hand side.  For example,
the GreaterThan class represents an inequal relationship where the
left-hand side is at least as big as the right side, if not bigger.  In
mathematical notation:</p>
<p>lhs &gt;= rhs</p>
<p>In total, there are four <code class="docutils literal notranslate"><span class="pre">*Than</span></code> classes, to represent the four
inequalities:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 68%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Class Name</p></th>
<th class="head"><p>Symbol</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan</p></td>
<td><p>(&gt;=)</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan</p></td>
<td><p>(&lt;=)</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan</p></td>
<td><p>(&gt;)</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan</p></td>
<td><p>(&lt;)</p></td>
</tr>
</tbody>
</table>
<p>All classes take two arguments, lhs and rhs.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 62%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Signature Example</p></th>
<th class="head"><p>Math equivalent</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>GreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;= rhs</p></td>
</tr>
<tr class="row-odd"><td><p>LessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;= rhs</p></td>
</tr>
<tr class="row-even"><td><p>StrictGreaterThan(lhs, rhs)</p></td>
<td><p>lhs &gt;  rhs</p></td>
</tr>
<tr class="row-odd"><td><p>StrictLessThan(lhs, rhs)</p></td>
<td><p>lhs &lt;  rhs</p></td>
</tr>
</tbody>
</table>
<p>In addition to the normal .lhs and .rhs of Relations, <code class="docutils literal notranslate"><span class="pre">*Than</span></code> inequality
objects also have the .lts and .gts properties, which represent the “less
than side” and “greater than side” of the operator.  Use of .lts and .gts
in an algorithm rather than .lhs and .rhs as an assumption of inequality
direction will make more explicit the intent of a certain section of code,
and will make it similarly more robust to client code changes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">GreaterThan</span><span class="p">,</span> <span class="n">StrictGreaterThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">LessThan</span><span class="p">,</span>    <span class="n">StrictLessThan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">And</span><span class="p">,</span> <span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">,</span> <span class="n">Rel</span><span class="p">,</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.relational</span> <span class="kn">import</span> <span class="n">Relational</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> &gt;= </span><span class="si">%s</span><span class="s1"> is the same as </span><span class="si">%s</span><span class="s1"> &lt;= </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">lts</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">gts</span><span class="p">)</span>
<span class="go">&#39;x &gt;= 1 is the same as 1 &lt;= x&#39;</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<p>One generally does not instantiate these classes directly, but uses various
convenience methods:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="n">Ge</span><span class="p">,</span> <span class="n">Gt</span><span class="p">,</span> <span class="n">Le</span><span class="p">,</span> <span class="n">Lt</span><span class="p">]:</span>  <span class="c1"># convenience wrappers</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x &gt;= 2</span>
<span class="go">x &gt; 2</span>
<span class="go">x &lt;= 2</span>
<span class="go">x &lt; 2</span>
</pre></div>
</div>
<p>Another option is to use the Python inequality operators (&gt;=, &gt;, &lt;=, &lt;)
directly.  Their main advantage over the Ge, Gt, Le, and Lt counterparts,
is that one can write a more “mathematical looking” statement rather than
littering the math with oddball function calls.  However there are certain
(minor) caveats of which to be aware (search for ‘gotcha’, below).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">2</span>
<span class="go">x &gt;= 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">==</span> <span class="n">Ge</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>However, it is also perfectly valid to instantiate a <code class="docutils literal notranslate"><span class="pre">*Than</span></code> class less
succinctly and less conveniently:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Rel</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;&gt;&quot;</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">StrictGreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GreaterThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &gt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">LessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt;= 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">StrictLessThan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">x &lt; 1</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>There are a couple of “gotchas” to be aware of when using Python’s
operators.</p>
<p>The first is that what your write is not always what you get:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">x &gt; 1</span>
</pre></div>
</div>
<p>Due to the order that Python parses a statement, it may
not immediately find two objects comparable.  When “1 &lt; x”
is evaluated, Python recognizes that the number 1 is a native
number and that x is <em>not</em>.  Because a native Python number does
not know how to compare itself with a SymPy object
Python will try the reflective operation, “x &gt; 1” and that is the
form that gets evaluated, hence returned.</p>
<p>If the order of the statement is important (for visual output to
the console, perhaps), one can work around this annoyance in a
couple ways:</p>
<ol class="arabic simple">
<li><p>“sympify” the literal before comparison</p></li>
</ol>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
<p>(2) use one of the wrappers or less succinct methods described
above</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Lt</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Relational</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="s2">&quot;&lt;&quot;</span><span class="p">)</span>
<span class="go">1 &lt; x</span>
</pre></div>
</div>
</div></blockquote>
<p>The second gotcha involves writing equality tests between relationals
when one or both sides of the test involve a literal relational:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">;</span> <span class="n">e</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">e</span>  <span class="c1"># neither side is a literal</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting True, too</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False</span>
<span class="go">x &lt; 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="o">!=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span>  <span class="c1"># expecting False or the same thing as before</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
<p>The solution for this case is to wrap literal relationals in
parentheses:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">==</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</div></blockquote>
<p>The third gotcha involves chained inequalities not involving
‘==’ or ‘!=’. Occasionally, one may be tempted to write:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">symbolic boolean expression has no truth value.</span>
</pre></div>
</div>
<p>Due to an implementation detail or decision of Python <a class="reference internal" href="#r125" id="id46"><span>[R125]</span></a>,
there is no way for SymPy to create a chained inequality with
that syntax so one must use And:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span> <span class="n">e</span> <span class="p">)</span>
<span class="go">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
</pre></div>
</div>
<p>Although this can also be done with the ‘&amp;’ operator, it cannot
be done with the ‘and’ operarator:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="go">(x &lt; y) &amp; (y &lt; z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">y</span> <span class="o">&lt;</span> <span class="n">z</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">cannot determine truth value of Relational</span>
</pre></div>
</div>
</div></blockquote>
<dl class="citation">
<dt class="label" id="r125"><span class="brackets"><a class="fn-backref" href="#id46">R125</a></span></dt>
<dd><p>This implementation detail is that Python provides no reliable
method to determine that a chained inequality is being built.
Chained comparison operators are evaluated pairwise, using “and”
logic (see
<a class="reference external" href="http://docs.python.org/reference/expressions.html#not-in">http://docs.python.org/reference/expressions.html#not-in</a>). This
is done in an efficient way, so that each object being compared
is only evaluated once and the comparison can short-circuit. For
example, <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">&gt;</span> <span class="pre">2</span> <span class="pre">&gt;</span> <span class="pre">3</span></code> is evaluated by Python as <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">&gt;</span> <span class="pre">2)</span> <span class="pre">and</span> <span class="pre">(2</span>
<span class="pre">&gt;</span> <span class="pre">3)</span></code>. The <code class="docutils literal notranslate"><span class="pre">and</span></code> operator coerces each side into a bool,
returning the object itself when it short-circuits. The bool of
the –Than operators will raise TypeError on purpose, because
SymPy cannot determine the mathematical ordering of symbolic
expressions. Thus, if we were to compute <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code>, with
<code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">y</span></code>, and <code class="docutils literal notranslate"><span class="pre">z</span></code> being Symbols, Python converts the
statement (roughly) into these steps:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>x &gt; y &gt; z</p></li>
<li><p>(x &gt; y) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject) and (y &gt; z)</p></li>
<li><p>(GreaterThanObject.__bool__()) and (y &gt; z)</p></li>
<li><p>TypeError</p></li>
</ol>
</div></blockquote>
<p>Because of the “and” added at step 2, the statement gets turned into a
weak ternary statement, and the first object’s __bool__ method will
raise TypeError.  Thus, creating a chained inequality is not possible.</p>
<blockquote>
<div><p>In Python, there is no way to override the <code class="docutils literal notranslate"><span class="pre">and</span></code> operator, or to
control how it short circuits, so it is impossible to make something
like <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span> <span class="pre">&gt;</span> <span class="pre">z</span></code> work.  There was a PEP to change this,
<span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0335"><strong>PEP 335</strong></a>, but it was officially closed in March, 2012.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.multidimensional">
<span id="multidimensional"></span><h2>multidimensional<a class="headerlink" href="#module-sympy.core.multidimensional" title="Permalink to this headline">¶</a></h2>
<section id="vectorize">
<h3>vectorize<a class="headerlink" href="#vectorize" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.multidimensional.vectorize">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.multidimensional.</span></span><span class="sig-name descname"><span class="pre">vectorize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">mdargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/multidimensional.py#L62-L138"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.multidimensional.vectorize" title="Permalink to this definition">¶</a></dt>
<dd><p>Generalizes a function taking scalars to accept multidimensional arguments.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">diff</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.multidimensional</span> <span class="kn">import</span> <span class="n">vectorize</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">Function</span><span class="p">,</span> <span class="s1">&#39;fgh&#39;</span><span class="p">))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@vectorize</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">vsin</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vsin</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="go">[sin(1), sin(x), sin(y)]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@vectorize</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">vdiff</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">diff</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vdiff</span><span class="p">([</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="n">h</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])</span>
<span class="go">[[Derivative(f(x, y, z), x), Derivative(f(x, y, z), y), Derivative(f(x, y, z), z)], [Derivative(g(x, y, z), x), Derivative(g(x, y, z), y), Derivative(g(x, y, z), z)], [Derivative(h(x, y, z), x), Derivative(h(x, y, z), y), Derivative(h(x, y, z), z)]]</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.function">
<span id="function"></span><h2>function<a class="headerlink" href="#module-sympy.core.function" title="Permalink to this headline">¶</a></h2>
<section id="lambda">
<h3>Lambda<a class="headerlink" href="#lambda" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.Lambda">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">Lambda</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">signature</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L1922-L2077"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Lambda" title="Permalink to this definition">¶</a></dt>
<dd><p>Lambda(x, expr) represents a lambda function similar to Python’s
‘lambda x: expr’. A function of several variables is written as
Lambda((x, y, …), expr).</p>
<p class="rubric">Examples</p>
<p>A simple example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Lambda</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Lambda</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">16</span>
</pre></div>
</div>
<p>For multivariate functions, use:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">t</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f2</span> <span class="o">=</span> <span class="n">Lambda</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">t</span><span class="p">),</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="o">**</span><span class="n">z</span> <span class="o">+</span> <span class="n">t</span><span class="o">**</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f2</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">73</span>
</pre></div>
</div>
<p>It is also possible to unpack tuple arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Lambda</span><span class="p">(</span> <span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="n">z</span><span class="p">)</span> <span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">6</span>
</pre></div>
</div>
<p>A handy shortcut for lots of arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Lambda</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="p">)</span>
<span class="go">x + y*z</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Lambda.bound_symbols">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">bound_symbols</span></span><a class="headerlink" href="#sympy.core.function.Lambda.bound_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>The variables used in the internal representation of the function</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Lambda.expr">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">expr</span></span><a class="headerlink" href="#sympy.core.function.Lambda.expr" title="Permalink to this definition">¶</a></dt>
<dd><p>The return value of the function</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Lambda.is_identity">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_identity</span></span><a class="headerlink" href="#sympy.core.function.Lambda.is_identity" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if this <code class="docutils literal notranslate"><span class="pre">Lambda</span></code> is an identity function.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Lambda.signature">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">signature</span></span><a class="headerlink" href="#sympy.core.function.Lambda.signature" title="Permalink to this definition">¶</a></dt>
<dd><p>The expected form of the arguments to be unpacked into variables</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Lambda.variables">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">variables</span></span><a class="headerlink" href="#sympy.core.function.Lambda.variables" title="Permalink to this definition">¶</a></dt>
<dd><p>The variables used in the internal representation of the function</p>
</dd></dl>

</dd></dl>

</section>
<section id="wildfunction">
<h3>WildFunction<a class="headerlink" href="#wildfunction" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.WildFunction">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">WildFunction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L951-L1023"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.WildFunction" title="Permalink to this definition">¶</a></dt>
<dd><p>A WildFunction function matches any function (with its arguments).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">WildFunction</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">WildFunction</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">Naturals0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: F_}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: f(x)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: cos(x)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: f(x, y)}</span>
</pre></div>
</div>
<p>To match functions with a given number of arguments, set <code class="docutils literal notranslate"><span class="pre">nargs</span></code> to the
desired value at instantiation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">WildFunction</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">{2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: f(x, y)}</span>
</pre></div>
</div>
<p>To match functions with a range of arguments, set <code class="docutils literal notranslate"><span class="pre">nargs</span></code> to a tuple
containing the desired number of arguments, e.g. if <code class="docutils literal notranslate"><span class="pre">nargs</span> <span class="pre">=</span> <span class="pre">(1,</span> <span class="pre">2)</span></code>
then functions with 1 or 2 arguments will be matched.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">WildFunction</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">{1, 2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: f(x)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
<span class="go">{F_: f(x, y)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="derivative">
<h3>Derivative<a class="headerlink" href="#derivative" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.Derivative">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">Derivative</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">variables</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L1026-L1908"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Derivative" title="Permalink to this definition">¶</a></dt>
<dd><p>Carries out differentiation of the given expression with respect to symbols.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Derivative</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Subs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">,</span> <span class="n">g</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;f g&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Function</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*x</span>
</pre></div>
</div>
<p>Denesting of derivatives retains the ordering of variables:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="n">y</span><span class="p">),</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(f(x, y), y, x)</span>
</pre></div>
</div>
<p>Contiguously identical symbols are merged into a tuple giving
the symbol and the count:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(f(x), (x, 2), y, x)</span>
</pre></div>
</div>
<p>If the derivative cannot be performed, and evaluate is True, the
order of the variables of differentiation will be made canonical:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">Derivative(f(x, y), x, y)</span>
</pre></div>
</div>
<p>Derivatives with respect to undefined functions can be calculated:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*f(x)</span>
</pre></div>
</div>
<p>Such derivatives will show up when the chain rule is used to
evalulate a derivative:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(f(g(x)), g(x))*Derivative(g(x), x)</span>
</pre></div>
</div>
<p>Substitution is used to represent derivatives of functions with
arguments that are not symbols or functions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="o">*</span><span class="n">Subs</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>Simplification of high-order derivatives:</p>
<p>Because there can be a significant amount of simplification that can be
done when multiple differentiations are performed, results will be
automatically simplified in a fairly conservative fashion unless the
keyword <code class="docutils literal notranslate"><span class="pre">simplify</span></code> is set to False.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">,</span> <span class="n">g</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;f,g&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Function</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">simplify</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">()</span>
<span class="go">136</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">count_ops</span><span class="p">()</span>
<span class="go">30</span>
</pre></div>
</div>
<p>Ordering of variables:</p>
<p>If evaluate is set to True and the expression cannot be evaluated, the
list of differentiation symbols will be sorted, that is, the expression is
assumed to have continuous derivatives up to the order asked.</p>
<p>Derivative wrt non-Symbols:</p>
<p>For the most part, one may not differentiate wrt non-symbols.
For example, we do not allow differentiation wrt <span class="math notranslate nohighlight">\(x*y\)</span> because
there are multiple ways of structurally defining where x*y appears
in an expression: a very strict definition would make
(x*y*z).diff(x*y) == 0. Derivatives wrt defined functions (like
cos(x)) are not allowed, either:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">Can&#39;t calculate derivative wrt x*y.</span>
</pre></div>
</div>
<p>To make it easier to work with variational calculus, however,
derivatives wrt AppliedUndef and Derivatives are allowed.
For example, in the Euler-Lagrange method one may write
F(t, u, v) where u = f(t) and v = f’(t). These variables can be
written explicitly as functions of time:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">t</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="n">U</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
</pre></div>
</div>
<p>The derivative wrt f(t) can be obtained directly:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">direct</span> <span class="o">=</span> <span class="n">F</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">U</span><span class="p">,</span> <span class="n">V</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">U</span><span class="p">)</span>
</pre></div>
</div>
<p>When differentiation wrt a non-Symbol is attempted, the non-Symbol
is temporarily converted to a Symbol while the differentiation
is performed and the same answer is obtained:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">indirect</span> <span class="o">=</span> <span class="n">F</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">U</span><span class="p">,</span> <span class="n">V</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">U</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">U</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">assert</span> <span class="n">direct</span> <span class="o">==</span> <span class="n">indirect</span>
</pre></div>
</div>
<p>The implication of this non-symbol replacement is that all
functions are treated as independent of other functions and the
symbols are independent of the functions that contain them:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">0</span>
</pre></div>
</div>
<p>It also means that derivatives are assumed to depend only
on the variables of differentiation, not on anything contained
within the expression being differentiated:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fx</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fx</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>  <span class="c1"># derivative depends on x, not F</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fxx</span> <span class="o">=</span> <span class="n">Fx</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fxx</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">Fx</span><span class="p">)</span>  <span class="c1"># derivative depends on x, not Fx</span>
<span class="go">0</span>
</pre></div>
</div>
<p>The last example can be made explicit by showing the replacement
of Fx in Fxx with y:</p>
<blockquote>
<div><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Fxx</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">Fx</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">Derivative(y, x)</span>
</pre></div>
</div>
<p>Since that in itself will evaluate to zero, differentiating
wrt Fx will also be zero:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
</div></blockquote>
<p>Replacing undefined functions with concrete expressions</p>
<p>One must be careful to replace undefined functions with expressions
that contain variables consistent with the function definition and
the variables of differentiation or else insconsistent result will
be obtained. Consider the following example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">y*Derivative(g(y), y) + g(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">y*Derivative(g(y), y)</span>
</pre></div>
</div>
<p>The results differ because <span class="math notranslate nohighlight">\(f(x)\)</span> was replaced with an expression
that involved both variables of differentiation. In the abstract
case, differentiation of <span class="math notranslate nohighlight">\(f(x)\)</span> by <span class="math notranslate nohighlight">\(y\)</span> is 0; in the concrete case,
the presence of <span class="math notranslate nohighlight">\(y\)</span> made that derivative nonvanishing and produced
the extra <span class="math notranslate nohighlight">\(g(y)\)</span> term.</p>
<p>Defining differentiation for an object</p>
<p>An object must define ._eval_derivative(symbol) method that returns
the differentiation result. This function only needs to consider the
non-trivial case where expr contains symbol and it should call the diff()
method internally (not _eval_derivative); Derivative should be the only
one to call _eval_derivative.</p>
<p>Any class can allow derivatives to be taken with respect to
itself (while indicating its scalar nature). See the
docstring of Expr._diff_wrt.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.function.Derivative._sort_variable_count" title="sympy.core.function.Derivative._sort_variable_count"><code class="xref py py-obj docutils literal notranslate"><span class="pre">_sort_variable_count</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Derivative._diff_wrt">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">_diff_wrt</span></span><a class="headerlink" href="#sympy.core.function.Derivative._diff_wrt" title="Permalink to this definition">¶</a></dt>
<dd><p>An expression may be differentiated wrt a Derivative if
it is in elementary form.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">Derivative</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">_diff_wrt</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">_diff_wrt</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">_diff_wrt</span>
<span class="go">False</span>
</pre></div>
</div>
<p>A Derivative might be an unevaluated form of what will not be
a valid variable of differentiation if evaluated. For example,</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">Derivative(f(x), x)*Derivative(f(f(x)), f(x))</span>
</pre></div>
</div>
<p>Such an expression will present the same ambiguities as arise
when dealing with any other product, like <code class="docutils literal notranslate"><span class="pre">2*x</span></code>, so <code class="docutils literal notranslate"><span class="pre">_diff_wrt</span></code>
is False:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Derivative</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">_diff_wrt</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Derivative._sort_variable_count">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">_sort_variable_count</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">vc</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L1492-L1587"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Derivative._sort_variable_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Sort (variable, count) pairs into canonical order while
retaining order of variables that do not commute during
differentiation:</p>
<ul class="simple">
<li><p>symbols and functions commute with each other</p></li>
<li><p>derivatives commute with each other</p></li>
<li><p>a derivative doesn’t commute with anything it contains</p></li>
<li><p>any other object is not allowed to commute if it has
free symbols in common with another object</p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Derivative</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vsort</span> <span class="o">=</span> <span class="n">Derivative</span><span class="o">.</span><span class="n">_sort_variable_count</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">h</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;f g h&#39;</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">Function</span><span class="p">)</span>
</pre></div>
</div>
<p>Contiguous items are collapsed into one pair:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vsort</span><span class="p">([(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)])</span>
<span class="go">[(x, 2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vsort</span><span class="p">([(</span><span class="n">y</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="mi">1</span><span class="p">)])</span>
<span class="go">[(y, 2), (f(x), 2)]</span>
</pre></div>
</div>
<p>Ordering is canonical.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">vsort0</span><span class="p">(</span><span class="o">*</span><span class="n">v</span><span class="p">):</span>
<span class="gp">... </span>    <span class="c1"># docstring helper to</span>
<span class="gp">... </span>    <span class="c1"># change vi -&gt; (vi, 0), sort, and return vi vals</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="p">[</span><span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">vsort</span><span class="p">([(</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="p">])]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vsort0</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">[x, y]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vsort0</span><span class="p">(</span><span class="n">g</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">f</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
<span class="go">[f(y), g(x), g(y)]</span>
</pre></div>
</div>
<p>Symbols are sorted as far to the left as possible but never
move to the left of a derivative having the same symbol in
its variables; the same applies to AppliedUndef which are
always sorted after Symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dfx</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">assert</span> <span class="n">vsort0</span><span class="p">(</span><span class="n">dfx</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="p">[</span><span class="n">y</span><span class="p">,</span> <span class="n">dfx</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">assert</span> <span class="n">vsort0</span><span class="p">(</span><span class="n">dfx</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="p">[</span><span class="n">dfx</span><span class="p">,</span> <span class="n">x</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Derivative.as_finite_difference">
<span class="sig-name descname"><span class="pre">as_finite_difference</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">points</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wrt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L1809-L1896"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Derivative.as_finite_difference" title="Permalink to this definition">¶</a></dt>
<dd><p>Expresses a Derivative instance as a finite difference.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>points</strong> : sequence or coefficient, optional</p>
<blockquote>
<div><p>If sequence: discrete values (length &gt;= order+1) of the
independent variable used for generating the finite
difference weights.
If it is a coefficient, it will be used as the step-size
for generating an equidistant sequence of length order+1
centered around <code class="docutils literal notranslate"><span class="pre">x0</span></code>. Default: 1 (step-size 1)</p>
</div></blockquote>
<p><strong>x0</strong> : number or Symbol, optional</p>
<blockquote>
<div><p>the value of the independent variable (<code class="docutils literal notranslate"><span class="pre">wrt</span></code>) at which the
derivative is to be approximated. Default: same as <code class="docutils literal notranslate"><span class="pre">wrt</span></code>.</p>
</div></blockquote>
<p><strong>wrt</strong> : Symbol, optional</p>
<blockquote>
<div><p>“with respect to” the variable for which the (partial)
derivative is to be approximated for. If not provided it
is required that the derivative is ordinary. Default: <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">h</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x h&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">()</span>
<span class="go">-f(x - 1/2) + f(x + 1/2)</span>
</pre></div>
</div>
<p>The default step size and number of points are 1 and
<code class="docutils literal notranslate"><span class="pre">order</span> <span class="pre">+</span> <span class="pre">1</span></code> respectively. We can change the step size by
passing a symbol as a parameter:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>
<span class="go">-f(-h/2 + x)/h + f(h/2 + x)/h</span>
</pre></div>
</div>
<p>We can also specify the discretized values to be used in a
sequence:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">h</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="mi">2</span><span class="o">*</span><span class="n">h</span><span class="p">])</span>
<span class="go">-3*f(x)/(2*h) + 2*f(h + x)/h - f(2*h + x)/(2*h)</span>
</pre></div>
</div>
<p>The algorithm is not restricted to use equidistant spacing, nor
do we need to make the approximation around <code class="docutils literal notranslate"><span class="pre">x0</span></code>, but we can get
an expression estimating the derivative at an offset:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="p">,</span> <span class="n">sq2</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">xl</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">-</span><span class="n">h</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">h</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">e</span><span class="o">*</span><span class="n">h</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">(</span><span class="n">xl</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">h</span><span class="o">*</span><span class="n">sq2</span><span class="p">)</span>  
<span class="go">2*h*((h + sqrt(2)*h)/(2*h) - (-sqrt(2)*h + h)/(2*h))*f(E*h + x)/...</span>
</pre></div>
</div>
<p>To approximate <code class="docutils literal notranslate"><span class="pre">Derivative</span></code> around <code class="docutils literal notranslate"><span class="pre">x0</span></code> using a non-equidistant
spacing step, the algorithm supports assignment of undefined
functions to <code class="docutils literal notranslate"><span class="pre">points</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dx</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;dx&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">(</span><span class="n">points</span><span class="o">=</span><span class="n">dx</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x0</span><span class="o">=</span><span class="n">x</span><span class="o">-</span><span class="n">h</span><span class="p">)</span>
<span class="go">-f(-h + x - dx(-h + x)/2)/dx(-h + x) + f(-h + x + dx(-h + x)/2)/dx(-h + x)</span>
</pre></div>
</div>
<p>Partial derivatives are also supported:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d2fdxdy</span><span class="o">=</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d2fdxdy</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">(</span><span class="n">wrt</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
<span class="go">-Derivative(f(x - 1/2, y), y) + Derivative(f(x + 1/2, y), y)</span>
</pre></div>
</div>
<p>We can apply <code class="docutils literal notranslate"><span class="pre">as_finite_difference</span></code> to <code class="docutils literal notranslate"><span class="pre">Derivative</span></code> instances in
compound expressions using <code class="docutils literal notranslate"><span class="pre">replace</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">42</span><span class="o">**</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="k">lambda</span> <span class="n">arg</span><span class="p">:</span> <span class="n">arg</span><span class="o">.</span><span class="n">is_Derivative</span><span class="p">,</span>
<span class="gp">... </span>    <span class="k">lambda</span> <span class="n">arg</span><span class="p">:</span> <span class="n">arg</span><span class="o">.</span><span class="n">as_finite_difference</span><span class="p">())</span>
<span class="go">42**(-f(x - 1/2) + f(x + 1/2)) + 1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="calculus/index.html#sympy.calculus.finite_diff.apply_finite_diff" title="sympy.calculus.finite_diff.apply_finite_diff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.calculus.finite_diff.apply_finite_diff</span></code></a>, <a class="reference internal" href="calculus/index.html#sympy.calculus.finite_diff.differentiate_finite" title="sympy.calculus.finite_diff.differentiate_finite"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.calculus.finite_diff.differentiate_finite</span></code></a>, <a class="reference internal" href="calculus/index.html#sympy.calculus.finite_diff.finite_diff_weights" title="sympy.calculus.finite_diff.finite_diff_weights"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.calculus.finite_diff.finite_diff_weights</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Derivative.doit_numerically">
<span class="sig-name descname"><span class="pre">doit_numerically</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">z0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L1622-L1640"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Derivative.doit_numerically" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate the derivative at z numerically.</p>
<p>When we can represent derivatives at a point, this should be folded
into the normal evalf. For now, we need a special method.</p>
</dd></dl>

</dd></dl>

</section>
<section id="diff">
<h3>diff<a class="headerlink" href="#diff" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.diff">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">diff</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2426-L2493"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.diff" title="Permalink to this definition">¶</a></dt>
<dd><p>Differentiate f with respect to symbols.</p>
<p class="rubric">Explanation</p>
<p>This is just a wrapper to unify .diff() and the Derivative class; its
interface is similar to that of integrate().  You can use the same
shortcuts for multiple variables as with Derivative.  For example,
diff(f(x), x, x, x) and diff(f(x), x, 3) both return the third derivative
of f(x).</p>
<p>You can pass evaluate=False to get an unevaluated Derivative class.  Note
that if there are 0 symbols (such as diff(f(x), x, 0), then the result will
be the function (the zeroth derivative), even if evaluate=False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">diff</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">)</span>
<span class="go">cos(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(f(x), (x, 3))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">Derivative(f(x), (x, 3))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">sin(x)*cos(y)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">))</span>
<span class="go">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">&lt;class &#39;sympy.core.function.Derivative&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">evaluate</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">sin</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">cos(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diff</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">))</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">specify differentiation variables to differentiate sin(x*y)</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">diff(sin(x))</span></code> syntax is meant only for convenience
in interactive sessions and should be avoided in library code.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.function.Derivative" title="sympy.core.function.Derivative"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Derivative</span></code></a></p>
<dl class="simple">
<dt><a class="reference internal" href="geometry/utils.html#sympy.geometry.util.idiff" title="sympy.geometry.util.idiff"><code class="xref py py-obj docutils literal notranslate"><span class="pre">idiff</span></code></a></dt><dd><p>computes the derivative implicitly</p>
</dd>
</dl>
</div>
<p class="rubric">References</p>
<p><a class="reference external" href="http://reference.wolfram.com/legacy/v5_2/Built-inFunctions/AlgebraicComputation/Calculus/D.html">http://reference.wolfram.com/legacy/v5_2/Built-inFunctions/AlgebraicComputation/Calculus/D.html</a></p>
</dd></dl>

</section>
<section id="functionclass">
<h3>FunctionClass<a class="headerlink" href="#functionclass" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.FunctionClass">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">FunctionClass</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L149-L254"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.FunctionClass" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for function classes. FunctionClass is a subclass of type.</p>
<p>Use Function(‘&lt;function name&gt;’ [ , signature ]) to create
undefined function classes.</p>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.FunctionClass.nargs">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">nargs</span></span><a class="headerlink" href="#sympy.core.function.FunctionClass.nargs" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a set of the allowed number of arguments for the function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If the function can take any number of arguments, the set of whole
numbers is returned:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">Naturals0</span>
</pre></div>
</div>
<p>If the function was initialized to accept one or more arguments, a
corresponding set will be returned:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">{1}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">{1, 2}</span>
</pre></div>
</div>
<p>The undefined function, after application, also has the nargs
attribute; the actual number of arguments is always available by
checking the <code class="docutils literal notranslate"><span class="pre">args</span></code> attribute:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">nargs</span>
<span class="go">Naturals0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="id47">
<h3>Function<a class="headerlink" href="#id47" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.Function">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">Function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L359-L828"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Function" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for applied mathematical functions.</p>
<p>It also serves as a constructor for undefined function classes.</p>
<p class="rubric">Examples</p>
<p>First example shows how to use Function as a constructor for undefined
function classes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">)(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span>
<span class="go">f</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">f(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span>
<span class="go">g(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(f(x), x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Derivative(g(x), x)</span>
</pre></div>
</div>
<p>Assumptions can be passed to Function, and if function is initialized with a
Symbol, the function inherits the name and assumptions associated with the Symbol:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f_real</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f_real</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f_real_inherit</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f_real_inherit</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Note that assumptions on a function are unrelated to the assumptions on
the variable it is called on. If you want to add a relationship, subclass
Function and define the appropriate <code class="docutils literal notranslate"><span class="pre">_eval_is_assumption</span></code> methods.</p>
<p>In the following example Function is used as a base class for
<code class="docutils literal notranslate"><span class="pre">my_func</span></code> that represents a mathematical function <em>my_func</em>. Suppose
that it is well known, that <em>my_func(0)</em> is <em>1</em> and <em>my_func</em> at infinity
goes to <em>0</em>, so we want those two simplifications to occur automatically.
Suppose also that <em>my_func(x)</em> is real exactly when <em>x</em> is real. Here is
an implementation that honours those requirements:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">I</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">my_func</span><span class="p">(</span><span class="n">Function</span><span class="p">):</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="nd">@classmethod</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">eval</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Number</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">is_zero</span><span class="p">:</span>
<span class="gp">... </span>                <span class="k">return</span> <span class="n">S</span><span class="o">.</span><span class="n">One</span>
<span class="gp">... </span>            <span class="k">elif</span> <span class="n">x</span> <span class="ow">is</span> <span class="n">S</span><span class="o">.</span><span class="n">Infinity</span><span class="p">:</span>
<span class="gp">... </span>                <span class="k">return</span> <span class="n">S</span><span class="o">.</span><span class="n">Zero</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_eval_is_real</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">is_real</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">S</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">my_func</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">my_func</span><span class="p">(</span><span class="n">oo</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">my_func</span><span class="p">(</span><span class="mf">3.54</span><span class="p">)</span><span class="o">.</span><span class="n">n</span><span class="p">()</span> <span class="c1"># Not yet implemented for my_func.</span>
<span class="go">my_func(3.54)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">my_func</span><span class="p">(</span><span class="n">I</span><span class="p">)</span><span class="o">.</span><span class="n">is_real</span>
<span class="go">False</span>
</pre></div>
</div>
<p>In order for <code class="docutils literal notranslate"><span class="pre">my_func</span></code> to become useful, several other methods would
need to be implemented. See source code of some of the already
implemented functions for more complete examples.</p>
<p>Also, if the function can take more than one argument, then <code class="docutils literal notranslate"><span class="pre">nargs</span></code>
must be defined, e.g. if <code class="docutils literal notranslate"><span class="pre">my_func</span></code> can take one or two arguments
then,</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">my_func</span><span class="p">(</span><span class="n">Function</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">nargs</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Function.as_base_exp">
<span class="sig-name descname"><span class="pre">as_base_exp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L649-L653"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Function.as_base_exp" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the method as the 2-tuple (base, exponent).</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Function.fdiff">
<span class="sig-name descname"><span class="pre">fdiff</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">argindex</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L778-L800"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Function.fdiff" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the first derivative of the function.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.function.Function.is_singular">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">is_singular</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L636-L647"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Function.is_singular" title="Permalink to this definition">¶</a></dt>
<dd><p>Tests whether the argument is an essential singularity
or a branch point, or the functions is non-holomorphic.</p>
</dd></dl>

</dd></dl>

<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Not all functions are the same</p>
<p>SymPy defines many functions (like <code class="docutils literal notranslate"><span class="pre">cos</span></code> and <code class="docutils literal notranslate"><span class="pre">factorial</span></code>). It also
allows the user to create generic functions which act as argument
holders. Such functions are created just like symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">f(2) + f(x)</span>
</pre></div>
</div>
<p>If you want to see which functions appear in an expression you can use
the atoms method:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">Function</span><span class="p">)</span>
<span class="go">{f(x), cos(x)}</span>
</pre></div>
</div>
<p>If you just want the function you defined, not SymPy functions, the
thing to search for is AppliedUndef:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">AppliedUndef</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">atoms</span><span class="p">(</span><span class="n">AppliedUndef</span><span class="p">)</span>
<span class="go">{f(x)}</span>
</pre></div>
</div>
</div>
</section>
<section id="subs">
<h3>Subs<a class="headerlink" href="#subs" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.Subs">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">Subs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">variables</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">point</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2080-L2423"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.Subs" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents unevaluated substitutions of an expression.</p>
<p><code class="docutils literal notranslate"><span class="pre">Subs(expr,</span> <span class="pre">x,</span> <span class="pre">x0)</span></code> represents the expression resulting
from substituting x with x0 in expr.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>An expression.</p>
</div></blockquote>
<p><strong>x</strong> : tuple, variable</p>
<blockquote>
<div><p>A variable or list of distinct variables.</p>
</div></blockquote>
<p><strong>x0</strong> : tuple or list of tuples</p>
<blockquote>
<div><p>A point or list of evaluation points
corresponding to those variables.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>In order to allow expressions to combine before doit is done, a
representation of the Subs expression is used internally to make
expressions that are superficially different compare the same:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">Subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">Subs</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
<span class="go">2*Subs(x, x, 0)</span>
</pre></div>
</div>
<p>This can lead to unexpected consequences when using methods
like <span class="math notranslate nohighlight">\(has\)</span> that are cached:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">s</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(True, False)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ss</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ss</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">ss</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">(True, False)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="p">,</span> <span class="n">ss</span>
<span class="go">(Subs(x, x, 0), Subs(y, y, 0))</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Subs</span><span class="p">,</span> <span class="n">Function</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Subs are created when a particular substitution cannot be made. The
x in the derivative cannot be replaced with 0 because 0 is not a
valid variables of differentiation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">Subs(Derivative(f(x), x), x, 0)</span>
</pre></div>
</div>
<p>Once f is known, the derivative and evaluation at 0 can be done:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">sin</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span> <span class="o">==</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="n">cos</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Subs can also be created directly with one or more variables:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Subs</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">+</span> <span class="n">z</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="go">Subs(z + f(x)*sin(y), (x, y), (0, 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">z + f(0)*sin(1)</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Subs.bound_symbols">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">bound_symbols</span></span><a class="headerlink" href="#sympy.core.function.Subs.bound_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>The variables to be evaluated</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Subs.expr">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">expr</span></span><a class="headerlink" href="#sympy.core.function.Subs.expr" title="Permalink to this definition">¶</a></dt>
<dd><p>The expression on which the substitution operates</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Subs.point">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">point</span></span><a class="headerlink" href="#sympy.core.function.Subs.point" title="Permalink to this definition">¶</a></dt>
<dd><p>The values for which the variables are to be substituted</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.function.Subs.variables">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">variables</span></span><a class="headerlink" href="#sympy.core.function.Subs.variables" title="Permalink to this definition">¶</a></dt>
<dd><p>The variables to be evaluated</p>
</dd></dl>

</dd></dl>

</section>
<section id="expand">
<h3>expand<a class="headerlink" href="#expand" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">modulus</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">power_base</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">power_exp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mul</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multinomial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">basic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2496-L2825"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand" title="Permalink to this definition">¶</a></dt>
<dd><p>Expand an expression using methods given as hints.</p>
<p class="rubric">Explanation</p>
<p>Hints evaluated unless explicitly set to False are:  <code class="docutils literal notranslate"><span class="pre">basic</span></code>, <code class="docutils literal notranslate"><span class="pre">log</span></code>,
<code class="docutils literal notranslate"><span class="pre">multinomial</span></code>, <code class="docutils literal notranslate"><span class="pre">mul</span></code>, <code class="docutils literal notranslate"><span class="pre">power_base</span></code>, and <code class="docutils literal notranslate"><span class="pre">power_exp</span></code> The following
hints are supported but not applied unless set to True:  <code class="docutils literal notranslate"><span class="pre">complex</span></code>,
<code class="docutils literal notranslate"><span class="pre">func</span></code>, and <code class="docutils literal notranslate"><span class="pre">trig</span></code>.  In addition, the following meta-hints are
supported by some or all of the other hints:  <code class="docutils literal notranslate"><span class="pre">frac</span></code>, <code class="docutils literal notranslate"><span class="pre">numer</span></code>,
<code class="docutils literal notranslate"><span class="pre">denom</span></code>, <code class="docutils literal notranslate"><span class="pre">modulus</span></code>, and <code class="docutils literal notranslate"><span class="pre">force</span></code>.  <code class="docutils literal notranslate"><span class="pre">deep</span></code> is supported by all
hints.  Additionally, subclasses of Expr may define their own hints or
meta-hints.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">basic</span></code> hint is used for any special rewriting of an object that
should be done automatically (along with the other hints like <code class="docutils literal notranslate"><span class="pre">mul</span></code>)
when expand is called. This is a catch-all hint to handle any sort of
expansion that may not be described by the existing hint names. To use
this hint an object should override the <code class="docutils literal notranslate"><span class="pre">_eval_expand_basic</span></code> method.
Objects may also define their own expand methods, which are not run by
default.  See the API section below.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">deep</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), things like arguments of
functions are recursively expanded.  Use <code class="docutils literal notranslate"><span class="pre">deep=False</span></code> to only expand on
the top level.</p>
<p>If the <code class="docutils literal notranslate"><span class="pre">force</span></code> hint is used, assumptions about variables will be ignored
in making the expansion.</p>
<p class="rubric">Hints</p>
<p>These hints are run by default</p>
<p class="rubric">Mul</p>
<p>Distributes multiplication over addition:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">y</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">z</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x*y + y*z</span>
</pre></div>
</div>
<p class="rubric">Multinomial</p>
<p>Expand (x + y + …)**n where n is a positive integer.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">multinomial</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**2 + 2*x*y + 2*x*z + y**2 + 2*y*z + z**2</span>
</pre></div>
</div>
<p class="rubric">Power_exp</p>
<p>Expand addition in exponents into multiplied bases.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_exp</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">exp(x)*exp(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_exp</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2**x*2**y</span>
</pre></div>
</div>
<p class="rubric">Power_base</p>
<p>Split powers of multiplied bases.</p>
<p>This only happens by default if assumptions allow, or if the
<code class="docutils literal notranslate"><span class="pre">force</span></code> meta-hint is used:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_base</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x*y)**z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_base</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**z*y**z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_base</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2**z*y**z</span>
</pre></div>
</div>
<p>Note that in some cases where this expansion always holds, SymPy performs
it automatically:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="go">x**2*y**2</span>
</pre></div>
</div>
<p class="rubric">Log</p>
<p>Pull out power of an argument as a coefficient and split logs products
into sums of logs.</p>
<p>Note that these only work if the arguments of the log function have the
proper assumptions–the arguments must be positive and the exponents must
be real–or else the <code class="docutils literal notranslate"><span class="pre">force</span></code> hint must be True:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">log</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">log(x**2*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*log(x) + log(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*log(x) + log(y)</span>
</pre></div>
</div>
<p class="rubric">Basic</p>
<p>This hint is intended primarily as a way for custom subclasses to enable
expansion by default.</p>
<p>These hints are not run by default:</p>
<p class="rubric">Complex</p>
<p>Split an expression into real and imaginary parts.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="nb">complex</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">re(x) + re(y) + I*im(x) + I*im(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="nb">complex</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">-I*sin(re(x))*sinh(im(x)) + cos(re(x))*cosh(im(x))</span>
</pre></div>
</div>
<p>Note that this is just a wrapper around <code class="docutils literal notranslate"><span class="pre">as_real_imag()</span></code>.  Most objects
that wish to redefine <code class="docutils literal notranslate"><span class="pre">_eval_expand_complex()</span></code> should consider
redefining <code class="docutils literal notranslate"><span class="pre">as_real_imag()</span></code> instead.</p>
<p class="rubric">Func</p>
<p>Expand other functions.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">gamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gamma</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">func</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x*gamma(x)</span>
</pre></div>
</div>
<p class="rubric">Trig</p>
<p>Do trigonometric expansions.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cos</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">trig</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">-sin(x)*sin(y) + cos(x)*cos(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">trig</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*sin(x)*cos(x)</span>
</pre></div>
</div>
<p>Note that the forms of <code class="docutils literal notranslate"><span class="pre">sin(n*x)</span></code> and <code class="docutils literal notranslate"><span class="pre">cos(n*x)</span></code> in terms of <code class="docutils literal notranslate"><span class="pre">sin(x)</span></code>
and <code class="docutils literal notranslate"><span class="pre">cos(x)</span></code> are not unique, due to the identity <span class="math notranslate nohighlight">\(\sin^2(x) + \cos^2(x)
= 1\)</span>.  The current implementation uses the form obtained from Chebyshev
polynomials, but this may change.  See <a class="reference external" href="http://mathworld.wolfram.com/Multiple-AngleFormulas.html">this MathWorld article</a> for more
information.</p>
<p class="rubric">Notes</p>
<ul>
<li><p>You can shut off unwanted methods:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">x*exp(x)*exp(y) + y*exp(x)*exp(y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">power_exp</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x*exp(x + y) + y*exp(x + y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(x + y)*exp(x)*exp(y)</span>
</pre></div>
</div>
</li>
<li><p>Use deep=False to only expand on the top level:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">exp(x)*exp(exp(x)*exp(y))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">exp(x)*exp(exp(x + y))</span>
</pre></div>
</div>
</li>
<li><p>Hints are applied in an arbitrary, but consistent order (in the current
implementation, they are applied in alphabetical order, except
multinomial comes before mul, but this may change).  Because of this,
some hints may prevent expansion by other hints if they are applied
first. For example, <code class="docutils literal notranslate"><span class="pre">mul</span></code> may distribute multiplications and prevent
<code class="docutils literal notranslate"><span class="pre">log</span></code> and <code class="docutils literal notranslate"><span class="pre">power_base</span></code> from expanding them. Also, if <code class="docutils literal notranslate"><span class="pre">mul</span></code> is
applied before <code class="docutils literal notranslate"><span class="pre">multinomial`,</span> <span class="pre">the</span> <span class="pre">expression</span> <span class="pre">might</span> <span class="pre">not</span> <span class="pre">be</span> <span class="pre">fully</span>
<span class="pre">distributed.</span> <span class="pre">The</span> <span class="pre">solution</span> <span class="pre">is</span> <span class="pre">to</span> <span class="pre">use</span> <span class="pre">the</span> <span class="pre">various</span> <span class="pre">``expand_hint</span></code> helper
functions or to use <code class="docutils literal notranslate"><span class="pre">hint=False</span></code> to this function to finely control
which hints are applied. Here are some examples:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand</span><span class="p">,</span> <span class="n">expand_mul</span><span class="p">,</span> <span class="n">expand_power_base</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y,z&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)))</span>
<span class="go">log(x) + log(y + z)</span>
</pre></div>
</div>
<p>Here, we see that <code class="docutils literal notranslate"><span class="pre">log</span></code> was applied before <code class="docutils literal notranslate"><span class="pre">mul</span></code>.  To get the mul
expanded form, either of the following will work:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_mul</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)))</span>
<span class="go">log(x*y + x*z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">)),</span> <span class="n">log</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">log(x*y + x*z)</span>
</pre></div>
</div>
<p>A similar thing can happen with the <code class="docutils literal notranslate"><span class="pre">power_base</span></code> hint:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">))</span><span class="o">**</span><span class="n">x</span><span class="p">)</span>
<span class="go">(x*y + x*z)**x</span>
</pre></div>
</div>
<p>To get the <code class="docutils literal notranslate"><span class="pre">power_base</span></code> expanded form, either of the following will
work:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">))</span><span class="o">**</span><span class="n">x</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x**x*(y + z)**x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="n">z</span><span class="p">))</span><span class="o">**</span><span class="n">x</span><span class="p">)</span>
<span class="go">x**x*(y + z)**x</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="n">x</span><span class="p">)</span>
<span class="go">y + y**2/x</span>
</pre></div>
</div>
<p>The parts of a rational expression can be targeted:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">frac</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x*y + y**2)/(x**2 + x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">numer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x*y + y**2)/(x*(x + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">denom</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">y*(x + y)/(x**2 + x)</span>
</pre></div>
</div>
</li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">modulus</span></code> meta-hint can be used to reduce the coefficients of an
expression post-expansion:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">9*x**2 + 6*x + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">modulus</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="go">4*x**2 + x + 1</span>
</pre></div>
</div>
</li>
<li><p>Either <code class="docutils literal notranslate"><span class="pre">expand()</span></code> the function or <code class="docutils literal notranslate"><span class="pre">.expand()</span></code> the method can be
used.  Both are equivalent:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">x**2 + 2*x + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">x**2 + 2*x + 1</span>
</pre></div>
</div>
</li>
</ul>
<p class="rubric">Api</p>
<p>Objects can define their own expand hints by defining
<code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code>.  The function should take the form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">_eval_expand_hint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">hints</span><span class="p">):</span>
    <span class="c1"># Only apply the method to the top-level expression</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>See also the example below.  Objects should define <code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code>
methods only if <code class="docutils literal notranslate"><span class="pre">hint</span></code> applies to that specific object.  The generic
<code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code> method defined in Expr will handle the no-op case.</p>
<p>Each hint should be responsible for expanding that hint only.
Furthermore, the expansion should be applied to the top-level expression
only.  <code class="docutils literal notranslate"><span class="pre">expand()</span></code> takes care of the recursion that happens when
<code class="docutils literal notranslate"><span class="pre">deep=True</span></code>.</p>
<p>You should only call <code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code> methods directly if you are
100% sure that the object has the method, as otherwise you are liable to
get unexpected <code class="docutils literal notranslate"><span class="pre">AttributeError``s.</span>&#160; <span class="pre">Note,</span> <span class="pre">again,</span> <span class="pre">that</span> <span class="pre">you</span> <span class="pre">do</span> <span class="pre">not</span> <span class="pre">need</span> <span class="pre">to</span>
<span class="pre">recursively</span> <span class="pre">apply</span> <span class="pre">the</span> <span class="pre">hint</span> <span class="pre">to</span> <span class="pre">args</span> <span class="pre">of</span> <span class="pre">your</span> <span class="pre">object:</span> <span class="pre">this</span> <span class="pre">is</span> <span class="pre">handled</span>
<span class="pre">automatically</span> <span class="pre">by</span> <span class="pre">``expand()</span></code>.  <code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code> should
generally not be used at all outside of an <code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code> method.
If you want to apply a specific expansion from within another method, use
the public <code class="docutils literal notranslate"><span class="pre">expand()</span></code> function, method, or <code class="docutils literal notranslate"><span class="pre">expand_hint()</span></code> functions.</p>
<p>In order for expand to work, objects must be rebuildable by their args,
i.e., <code class="docutils literal notranslate"><span class="pre">obj.func(*obj.args)</span> <span class="pre">==</span> <span class="pre">obj</span></code> must hold.</p>
<p>Expand methods are passed <code class="docutils literal notranslate"><span class="pre">**hints</span></code> so that expand hints may use
‘metahints’–hints that control how different expand methods are applied.
For example, the <code class="docutils literal notranslate"><span class="pre">force=True</span></code> hint described above that causes
<code class="docutils literal notranslate"><span class="pre">expand(log=True)</span></code> to ignore assumptions is such a metahint.  The
<code class="docutils literal notranslate"><span class="pre">deep</span></code> meta-hint is handled exclusively by <code class="docutils literal notranslate"><span class="pre">expand()</span></code> and is not
passed to <code class="docutils literal notranslate"><span class="pre">_eval_expand_hint()</span></code> methods.</p>
<p>Note that expansion hints should generally be methods that perform some
kind of ‘expansion’.  For hints that simply rewrite an expression, use the
.rewrite() API.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Expr</span><span class="p">,</span> <span class="n">sympify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="n">Expr</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">args</span> <span class="o">=</span> <span class="n">sympify</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">Expr</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_eval_expand_double</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">hints</span><span class="p">):</span>
<span class="gp">... </span>        <span class="sd">&#39;&#39;&#39;</span>
<span class="gp">... </span><span class="sd">        Doubles the args of MyClass.</span>
<span class="gp">...</span><span class="sd"></span>
<span class="gp">... </span><span class="sd">        If there more than four args, doubling is not performed,</span>
<span class="gp">... </span><span class="sd">        unless force=True is also used (False by default).</span>
<span class="gp">... </span><span class="sd">        &#39;&#39;&#39;</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="ow">not</span> <span class="n">force</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">return</span> <span class="bp">self</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">))</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">MyClass</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">MyClass(1, 2, MyClass(3, 4))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">double</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">MyClass(1, 2, MyClass(3, 4, 3, 4), 1, 2, MyClass(3, 4, 3, 4))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">double</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">MyClass(1, 2, MyClass(3, 4), 1, 2, MyClass(3, 4))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">double</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">MyClass(1, 2, 3, 4, 5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="n">double</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">MyClass(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.function.expand_log" title="sympy.core.function.expand_log"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_log</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_mul" title="sympy.core.function.expand_mul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_mul</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_multinomial" title="sympy.core.function.expand_multinomial"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_multinomial</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_complex" title="sympy.core.function.expand_complex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_complex</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_trig" title="sympy.core.function.expand_trig"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_trig</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_power_base" title="sympy.core.function.expand_power_base"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_power_base</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_power_exp" title="sympy.core.function.expand_power_exp"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_power_exp</span></code></a>, <a class="reference internal" href="#sympy.core.function.expand_func" title="sympy.core.function.expand_func"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand_func</span></code></a>, <a class="reference internal" href="simplify/simplify.html#sympy.simplify.hyperexpand.hyperexpand" title="sympy.simplify.hyperexpand.hyperexpand"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.simplify.hyperexpand.hyperexpand</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="poleerror">
<h3>PoleError<a class="headerlink" href="#poleerror" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.function.PoleError">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">PoleError</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L96-L97"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.PoleError" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</section>
<section id="count-ops">
<h3>count_ops<a class="headerlink" href="#count-ops" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.count_ops">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">count_ops</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">visual</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L3060-L3270"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.count_ops" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a representation (integer or expression) of the operations in expr.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>If expr is an iterable, the sum of the op counts of the
items will be returned.</p>
</div></blockquote>
<p><strong>visual</strong> : bool, optional</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code> (default) then the sum of the coefficients of the
visual expression will be returned.
If <code class="docutils literal notranslate"><span class="pre">True</span></code> then the number of each type of operation is shown
with the core class types (or their virtual equivalent) multiplied by the
number of times they occur.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">count_ops</span>
</pre></div>
</div>
<p>Although there isn’t a SUB object, minus signs are interpreted as
either negations or subtractions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">SUB</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">NEG</span>
</pre></div>
</div>
<p>Here, there are two Adds and a Pow:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*ADD + POW</span>
</pre></div>
</div>
<p>In the following, an Add, Mul, Pow and two functions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">ADD + MUL + POW + 2*SIN</span>
</pre></div>
</div>
<p>for a total of 5:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">5</span>
</pre></div>
</div>
<p>Note that “what you type” is not always what you get. The expression
1/x/y is translated by sympy into 1/(x*y) so it gives a DIV and MUL rather
than two DIVs:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">count_ops</span><span class="p">(</span><span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">DIV + MUL</span>
</pre></div>
</div>
<p>The visual option can be used to demonstrate the difference in
operations for expressions in different forms. Here, the Horner
representation is compared with the expanded form of a polynomial:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span><span class="o">=</span><span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="n">x</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">count_ops</span><span class="p">(</span><span class="n">eq</span><span class="o">.</span><span class="n">expand</span><span class="p">(),</span> <span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">-</span> <span class="n">count_ops</span><span class="p">(</span><span class="n">eq</span><span class="p">,</span> <span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">-MUL + 3*POW</span>
</pre></div>
</div>
<p>The count_ops function also handles iterables:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">count_ops</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">],</span> <span class="n">visual</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">count_ops</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">],</span> <span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">ADD + SIN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">count_ops</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">},</span> <span class="n">visual</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">2*ADD + SIN</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-mul">
<h3>expand_mul<a class="headerlink" href="#expand-mul" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_mul">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2846-L2861"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the mul hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">expand_mul</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_mul</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">x*exp(x + y)*log(x*y**2) + y*exp(x + y)*log(x*y**2)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-log">
<h3>expand_log<a class="headerlink" href="#expand-log" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_log">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">factor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2882-L2911"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_log" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the log hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">expand_log</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_log</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">(x + y)*(log(x) + 2*log(y))*exp(x + y)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-func">
<h3>expand_func<a class="headerlink" href="#expand-func" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_func">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_func</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2914-L2929"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_func" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the func hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_func</span><span class="p">,</span> <span class="n">gamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_func</span><span class="p">(</span><span class="n">gamma</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x*(x + 1)*gamma(x)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-trig">
<h3>expand_trig<a class="headerlink" href="#expand-trig" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_trig">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_trig</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2932-L2947"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_trig" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the trig hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_trig</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_trig</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">))</span>
<span class="go">(x + y)*(sin(x)*cos(y) + sin(y)*cos(x))</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-complex">
<h3>expand_complex<a class="headerlink" href="#expand-complex" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_complex">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_complex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2950-L2971"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_complex" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the complex hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_complex</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_complex</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">z</span><span class="p">))</span>
<span class="go">I*exp(re(z))*sin(im(z)) + exp(re(z))*cos(im(z))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_complex</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">I</span><span class="p">))</span>
<span class="go">sqrt(2)/2 + sqrt(2)*I/2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.expr.Expr.as_real_imag" title="sympy.core.expr.Expr.as_real_imag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.expr.Expr.as_real_imag</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="expand-multinomial">
<h3>expand_multinomial<a class="headerlink" href="#expand-multinomial" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_multinomial">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_multinomial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2864-L2879"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_multinomial" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the multinomial hint.  See the expand
docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">expand_multinomial</span><span class="p">,</span> <span class="n">exp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_multinomial</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">x**2 + 2*x*exp(x + 1) + exp(2*x + 2)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-power-exp">
<h3>expand_power_exp<a class="headerlink" href="#expand-power-exp" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_power_exp">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_power_exp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L3042-L3057"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_power_exp" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the power_exp hint.</p>
<p>See the expand docstring for more information.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_power_exp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_exp</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">x**2*x**y</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="expand-power-base">
<h3>expand_power_base<a class="headerlink" href="#expand-power-base" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.expand_power_base">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">expand_power_base</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L2974-L3039"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.expand_power_base" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around expand that only uses the power_base hint.</p>
<p>A wrapper to expand(power_base=True) which separates a power with a base
that is a Mul into a product of powers, without performing any other
expansions, provided that assumptions about the power’s base and exponent
allow.</p>
<p>deep=False (default is True) will only apply to the top-level expression.</p>
<p>force=True (default is False) will cause the expansion to ignore
assumptions about the base and exponent. When False, the expansion will
only happen if the base is non-negative or the exponent is an integer.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">expand_power_base</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">exp</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="go">x**2*y**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="n">y</span>
<span class="go">(2*x)**y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">2**y*x**y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">)</span>
<span class="go">(x*y)**z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**z*y**z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">(</span><span class="n">sin</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">),</span> <span class="n">deep</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">sin((x*y)**z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">(</span><span class="n">sin</span><span class="p">((</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="n">z</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">sin(x**z*y**z)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">**</span><span class="n">y</span> <span class="o">+</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">**</span><span class="n">y</span><span class="p">)</span>
<span class="go">2**y*sin(x)**y + 2**y*cos(x)**y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">**</span><span class="n">x</span><span class="p">)</span>
<span class="go">2**x*exp(y)**x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">**</span><span class="n">y</span><span class="p">)</span>
<span class="go">2**y*cos(x)**y</span>
</pre></div>
</div>
<p>Notice that sums are left untouched. If this is not the desired behavior,
apply full <code class="docutils literal notranslate"><span class="pre">expand()</span></code> to the expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">(((</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">z</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">z**2*(x + y)**2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(((</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">z</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">x**2*z**2 + 2*x*y*z**2 + y**2*z**2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expand_power_base</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">z</span><span class="p">))</span>
<span class="go">2**(z + 1)*y**(z + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">z</span><span class="p">))</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="go">2*2**z*y*y**z</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.function.expand" title="sympy.core.function.expand"><code class="xref py py-obj docutils literal notranslate"><span class="pre">expand</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="nfloat">
<h3>nfloat<a class="headerlink" href="#nfloat" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.function.nfloat">
<span class="sig-prename descclassname"><span class="pre">sympy.core.function.</span></span><span class="sig-name descname"><span class="pre">nfloat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">15</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exponent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dkeys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/function.py#L3273-L3358"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.function.nfloat" title="Permalink to this definition">¶</a></dt>
<dd><p>Make all Rationals in expr Floats except those in exponents
(unless the exponents flag is set to True). When processing
dictionaries, don’t modify the keys unless <code class="docutils literal notranslate"><span class="pre">dkeys=True</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">nfloat</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sqrt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nfloat</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">4</span> <span class="o">+</span> <span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
<span class="go">x**4 + 0.5*x + sqrt(y) + 1.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nfloat</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">4</span> <span class="o">+</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">exponent</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">x**4.0 + y**0.5</span>
</pre></div>
</div>
<p>Container types are not modified:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">nfloat</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span> <span class="ow">is</span> <span class="nb">tuple</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.evalf">
<span id="evalf"></span><h2>evalf<a class="headerlink" href="#module-sympy.core.evalf" title="Permalink to this headline">¶</a></h2>
<section id="evalfmixin">
<h3>EvalfMixin<a class="headerlink" href="#evalfmixin" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.evalf.EvalfMixin">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.evalf.</span></span><span class="sig-name descname"><span class="pre">EvalfMixin</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/evalf.py#L1420-L1593"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.evalf.EvalfMixin" title="Permalink to this definition">¶</a></dt>
<dd><p>Mixin class adding evalf capabililty.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.evalf.EvalfMixin.evalf">
<span class="sig-name descname"><span class="pre">evalf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">15</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">100</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">chop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quad</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/evalf.py#L1425-L1542"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.evalf.EvalfMixin.evalf" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate the given formula to an accuracy of <em>n</em> digits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>subs</strong> : dict, optional</p>
<blockquote>
<div><p>Substitute numerical values for symbols, e.g.
<code class="docutils literal notranslate"><span class="pre">subs={x:3,</span> <span class="pre">y:1+pi}</span></code>. The substitutions must be given as a
dictionary.</p>
</div></blockquote>
<p><strong>maxn</strong> : int, optional</p>
<blockquote>
<div><p>Allow a maximum temporary working precision of maxn digits.</p>
</div></blockquote>
<p><strong>chop</strong> : bool or number, optional</p>
<blockquote>
<div><p>Specifies how to replace tiny real or imaginary parts in
subresults by exact zeros.</p>
<p>When <code class="docutils literal notranslate"><span class="pre">True</span></code> the chop value defaults to standard precision.</p>
<p>Otherwise the chop value is used to determine the
magnitude of “small” for purposes of chopping.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">N</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mf">1e-4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">0.000100000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="mf">1e-5</span><span class="p">)</span>
<span class="go">0.000100000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>strict</strong> : bool, optional</p>
<blockquote>
<div><p>Raise <code class="docutils literal notranslate"><span class="pre">PrecisionExhausted</span></code> if any subresult fails to
evaluate to full accuracy, given the available maxprec.</p>
</div></blockquote>
<p><strong>quad</strong> : str, optional</p>
<blockquote>
<div><p>Choose algorithm for numerical quadrature. By default,
tanh-sinh quadrature is used. For oscillatory
integrals on an infinite interval, try <code class="docutils literal notranslate"><span class="pre">quad='osc'</span></code>.</p>
</div></blockquote>
<p><strong>verbose</strong> : bool, optional</p>
<blockquote>
<div><p>Print debug information.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>When Floats are naively substituted into an expression,
precision errors may adversely affect the result. For example,
adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
then subtracted, the result will be 0.
That is exactly what happens in the following:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span> <span class="mf">1e16</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">z</span><span class="p">:</span> <span class="mf">1e16</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">-</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Using the subs argument for evalf is the accurate way to
evaluate such an expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">-</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="n">subs</span><span class="o">=</span><span class="n">values</span><span class="p">)</span>
<span class="go">1.00000000000000</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.evalf.EvalfMixin.n">
<span class="sig-name descname"><span class="pre">n</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">15</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">100</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">chop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quad</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/evalf.py#L1425-L1542"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.evalf.EvalfMixin.n" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate the given formula to an accuracy of <em>n</em> digits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>subs</strong> : dict, optional</p>
<blockquote>
<div><p>Substitute numerical values for symbols, e.g.
<code class="docutils literal notranslate"><span class="pre">subs={x:3,</span> <span class="pre">y:1+pi}</span></code>. The substitutions must be given as a
dictionary.</p>
</div></blockquote>
<p><strong>maxn</strong> : int, optional</p>
<blockquote>
<div><p>Allow a maximum temporary working precision of maxn digits.</p>
</div></blockquote>
<p><strong>chop</strong> : bool or number, optional</p>
<blockquote>
<div><p>Specifies how to replace tiny real or imaginary parts in
subresults by exact zeros.</p>
<p>When <code class="docutils literal notranslate"><span class="pre">True</span></code> the chop value defaults to standard precision.</p>
<p>Otherwise the chop value is used to determine the
magnitude of “small” for purposes of chopping.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">N</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mf">1e-4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">0.000100000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="mf">1e-5</span><span class="p">)</span>
<span class="go">0.000100000000000000</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">chop</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>strict</strong> : bool, optional</p>
<blockquote>
<div><p>Raise <code class="docutils literal notranslate"><span class="pre">PrecisionExhausted</span></code> if any subresult fails to
evaluate to full accuracy, given the available maxprec.</p>
</div></blockquote>
<p><strong>quad</strong> : str, optional</p>
<blockquote>
<div><p>Choose algorithm for numerical quadrature. By default,
tanh-sinh quadrature is used. For oscillatory
integrals on an infinite interval, try <code class="docutils literal notranslate"><span class="pre">quad='osc'</span></code>.</p>
</div></blockquote>
<p><strong>verbose</strong> : bool, optional</p>
<blockquote>
<div><p>Print debug information.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>When Floats are naively substituted into an expression,
precision errors may adversely affect the result. For example,
adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
then subtracted, the result will be 0.
That is exactly what happens in the following:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span> <span class="mf">1e16</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">z</span><span class="p">:</span> <span class="mf">1e16</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">-</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p>Using the subs argument for evalf is the accurate way to
evaluate such an expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">-</span> <span class="n">z</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(</span><span class="n">subs</span><span class="o">=</span><span class="n">values</span><span class="p">)</span>
<span class="go">1.00000000000000</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="precisionexhausted">
<h3>PrecisionExhausted<a class="headerlink" href="#precisionexhausted" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.evalf.PrecisionExhausted">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.evalf.</span></span><span class="sig-name descname"><span class="pre">PrecisionExhausted</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/evalf.py#L50-L51"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.evalf.PrecisionExhausted" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</section>
<section id="n">
<h3>N<a class="headerlink" href="#n" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.evalf.N">
<span class="sig-prename descclassname"><span class="pre">sympy.core.evalf.</span></span><span class="sig-name descname"><span class="pre">N</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">15</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/evalf.py#L1596-L1619"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.evalf.N" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls x.evalf(n, **options).</p>
<p class="rubric">Explanations</p>
<p>Both .n() and N() are equivalent to .evalf(); use the one that you like better.
See also the docstring of .evalf() for information on the options.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">N</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">k</span><span class="o">**</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">Sum(k**(-k), (k, 1, oo))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">1.291</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.containers">
<span id="containers"></span><h2>containers<a class="headerlink" href="#module-sympy.core.containers" title="Permalink to this headline">¶</a></h2>
<section id="tuple">
<h3>Tuple<a class="headerlink" href="#tuple" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.containers.Tuple">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.containers.</span></span><span class="sig-name descname"><span class="pre">Tuple</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L17-L143"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Tuple" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around the builtin tuple object.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>sympify</strong> : bool</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code>, <code class="docutils literal notranslate"><span class="pre">sympify</span></code> is not called on <code class="docutils literal notranslate"><span class="pre">args</span></code>. This
can be used for speedups for very large tuples where the
elements are known to already be sympy objects.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>The Tuple is a subclass of Basic, so that it works well in the
SymPy framework.  The wrapped tuple is available as self.args, but
you can also access elements or slices with [:] syntax.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.containers</span> <span class="kn">import</span> <span class="n">Tuple</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b c d&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Tuple</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
<span class="go">(b, c)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Tuple</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
<span class="go">(d, b, c)</span>
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Tuple.index">
<span class="sig-name descname"><span class="pre">index</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L123-L143"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Tuple.index" title="Permalink to this definition">¶</a></dt>
<dd><p>Searches and returns the first index of the value.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Tuple.tuple_count">
<span class="sig-name descname"><span class="pre">tuple_count</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L119-L121"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Tuple.tuple_count" title="Permalink to this definition">¶</a></dt>
<dd><p>T.count(value) -&gt; integer – return number of occurrences of value</p>
</dd></dl>

</dd></dl>

</section>
<section id="dict">
<h3>Dict<a class="headerlink" href="#dict" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.containers.Dict">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.containers.</span></span><span class="sig-name descname"><span class="pre">Dict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L188-L306"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around the builtin dict object</p>
<p class="rubric">Explanation</p>
<p>The Dict is a subclass of Basic, so that it works well in the
SymPy framework.  Because it is immutable, it may be included
in sets, but its values must all be given at instantiation and
cannot be changed afterwards.  Otherwise it behaves identically
to the Python dict.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.containers</span> <span class="kn">import</span> <span class="n">Dict</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">Dict</span><span class="p">({</span><span class="mi">1</span><span class="p">:</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="s1">&#39;two&#39;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">D</span><span class="p">:</span>
<span class="gp">... </span>   <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="gp">... </span>       <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">D</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
<span class="go">1 one</span>
</pre></div>
</div>
<p>The args are sympified so the 1 and 2 are Integers and the values
are Symbols. Queries automatically sympify args so the following work:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="ow">in</span> <span class="n">D</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;one&#39;</span><span class="p">))</span> <span class="c1"># searches keys and values</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;one&#39;</span> <span class="ow">in</span> <span class="n">D</span> <span class="c1"># not in the keys</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">one</span>
</pre></div>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.core.containers.Dict.args">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">args</span></span><a class="headerlink" href="#sympy.core.containers.Dict.args" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a tuple of arguments of ‘self’.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.basic.Basic.args" title="sympy.core.basic.Basic.args"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.basic.Basic.args</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Dict.get">
<span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L284-L290"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Dict.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the value for key if the key is in the dictionary.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Dict.items">
<span class="sig-name descname"><span class="pre">items</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L263-L266"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Dict.items" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a set-like object providing a view on dict’s items.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Dict.keys">
<span class="sig-name descname"><span class="pre">keys</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L268-L270"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Dict.keys" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of the dict’s keys.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.core.containers.Dict.values">
<span class="sig-name descname"><span class="pre">values</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/containers.py#L272-L274"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.containers.Dict.values" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of the dict’s values.</p>
</dd></dl>

</dd></dl>

</section>
</section>
<section id="module-sympy.core.compatibility">
<span id="compatibility"></span><h2>compatibility<a class="headerlink" href="#module-sympy.core.compatibility" title="Permalink to this headline">¶</a></h2>
<section id="iterable">
<h3>iterable<a class="headerlink" href="#iterable" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.compatibility.iterable">
<span class="sig-prename descclassname"><span class="pre">sympy.core.compatibility.</span></span><span class="sig-name descname"><span class="pre">iterable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">i</span></em>, <em class="sig-param"><span class="pre">exclude=(&lt;class</span> <span class="pre">'str'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'dict'&gt;</span></em>, <em class="sig-param"><span class="pre">&lt;class</span> <span class="pre">'sympy.core.compatibility.NotIterable'&gt;)</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/compatibility.py#L150-L205"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.compatibility.iterable" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a boolean indicating whether <code class="docutils literal notranslate"><span class="pre">i</span></code> is SymPy iterable.
True also indicates that the iterator is finite, e.g. you can
call list(…) on the instance.</p>
<p>When SymPy is working with iterables, it is almost always assuming
that the iterable is not a string or a mapping, so those are excluded
by default. If you want a pure Python definition, make exclude=None. To
exclude multiple items, pass them as a tuple.</p>
<p>You can also set the _iterable attribute to True or False on your class,
which will override the checks here, including the exclude test.</p>
<p>As a rule of thumb, some SymPy functions use this to check if they should
recursively map over an object. If an object is technically iterable in
the Python sense but does not desire this behavior (e.g., because its
iteration is not finite, or because iteration might induce an unwanted
computation), it should disable it by setting the _iterable attribute to False.</p>
<p>See also: is_sequence</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">iterable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Tuple</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">things</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">],</span> <span class="p">(</span><span class="mi">1</span><span class="p">,),</span> <span class="nb">set</span><span class="p">([</span><span class="mi">1</span><span class="p">]),</span> <span class="n">Tuple</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">j</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]),</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">},</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">things</span><span class="p">:</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">iterable</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="nb">type</span><span class="p">(</span><span class="n">i</span><span class="p">)))</span>
<span class="go">True &lt;... &#39;list&#39;&gt;</span>
<span class="go">True &lt;... &#39;tuple&#39;&gt;</span>
<span class="go">True &lt;... &#39;set&#39;&gt;</span>
<span class="go">True &lt;class &#39;sympy.core.containers.Tuple&#39;&gt;</span>
<span class="go">True &lt;... &#39;generator&#39;&gt;</span>
<span class="go">False &lt;... &#39;dict&#39;&gt;</span>
<span class="go">False &lt;... &#39;str&#39;&gt;</span>
<span class="go">False &lt;... &#39;int&#39;&gt;</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">iterable</span><span class="p">({},</span> <span class="n">exclude</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">iterable</span><span class="p">({},</span> <span class="n">exclude</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">iterable</span><span class="p">(</span><span class="s2">&quot;no&quot;</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="is-sequence">
<h3>is_sequence<a class="headerlink" href="#is-sequence" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.compatibility.is_sequence">
<span class="sig-prename descclassname"><span class="pre">sympy.core.compatibility.</span></span><span class="sig-name descname"><span class="pre">is_sequence</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">include</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/compatibility.py#L208-L245"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.compatibility.is_sequence" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a boolean indicating whether <code class="docutils literal notranslate"><span class="pre">i</span></code> is a sequence in the SymPy
sense. If anything that fails the test below should be included as
being a sequence for your application, set ‘include’ to that object’s
type; multiple types should be passed as a tuple of types.</p>
<p>Note: although generators can generate a sequence, they often need special
handling to make sure their elements are captured before the generator is
exhausted, so these are not included by default in the definition of a
sequence.</p>
<p>See also: iterable</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">is_sequence</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">types</span> <span class="kn">import</span> <span class="n">GeneratorType</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">([])</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">(</span><span class="nb">set</span><span class="p">())</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">,</span> <span class="n">include</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">generator</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="s1">&#39;abc&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">(</span><span class="n">generator</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_sequence</span><span class="p">(</span><span class="n">generator</span><span class="p">,</span> <span class="n">include</span><span class="o">=</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">GeneratorType</span><span class="p">))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="as-int">
<h3>as_int<a class="headerlink" href="#as-int" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.compatibility.as_int">
<span class="sig-prename descclassname"><span class="pre">sympy.core.compatibility.</span></span><span class="sig-name descname"><span class="pre">as_int</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/compatibility.py#L248-L312"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.compatibility.as_int" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the argument to a builtin integer.</p>
<p>The return value is guaranteed to be equal to the input. ValueError is
raised if the input has a non-integral value. When <code class="docutils literal notranslate"><span class="pre">strict</span></code> is True, this
uses <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__index__">__index__</a>
and when it is False it uses <code class="docutils literal notranslate"><span class="pre">int</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.compatibility</span> <span class="kn">import</span> <span class="n">as_int</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sqrt</span><span class="p">,</span> <span class="n">S</span>
</pre></div>
</div>
<p>The function is primarily concerned with sanitizing input for
functions that need to work with builtin integers, so anything that
is unambiguously an integer should be returned as an int:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">as_int</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">3</span>
</pre></div>
</div>
<p>Floats, being of limited precision, are not assumed to be exact and
will raise an error unless the <code class="docutils literal notranslate"><span class="pre">strict</span></code> flag is False. This
precision issue becomes apparent for large floating point numbers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">big</span> <span class="o">=</span> <span class="mf">1e23</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">big</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">float</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">big</span> <span class="o">==</span> <span class="nb">int</span><span class="p">(</span><span class="n">big</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">as_int</span><span class="p">(</span><span class="n">big</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">... is not an integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">as_int</span><span class="p">(</span><span class="n">big</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">99999999999999991611392</span>
</pre></div>
</div>
<p>Input that might be a complex representation of an integer value is
also rejected by default:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">one</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span> <span class="o">-</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">int</span><span class="p">(</span><span class="n">one</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">as_int</span><span class="p">(</span><span class="n">one</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">... is not an integer</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.exprtools">
<span id="exprtools"></span><h2>exprtools<a class="headerlink" href="#module-sympy.core.exprtools" title="Permalink to this headline">¶</a></h2>
<section id="gcd-terms">
<h3>gcd_terms<a class="headerlink" href="#gcd-terms" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.exprtools.gcd_terms">
<span class="sig-prename descclassname"><span class="pre">sympy.core.exprtools.</span></span><span class="sig-name descname"><span class="pre">gcd_terms</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">terms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">isprimitive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fraction</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/exprtools.py#L987-L1112"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.exprtools.gcd_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the GCD of <code class="docutils literal notranslate"><span class="pre">terms</span></code> and put them together.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>terms</strong> : Expr</p>
<blockquote>
<div><p>Can be an expression or a non-Basic sequence of expressions
which will be handled as though they are terms from a sum.</p>
</div></blockquote>
<p><strong>isprimitive</strong> : bool, optional</p>
<blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">isprimitive</span></code> is True the _gcd_terms will not run the primitive
method on the terms.</p>
</div></blockquote>
<p><strong>clear</strong> : bool, optional</p>
<blockquote>
<div><p>It controls the removal of integers from the denominator of an Add
expression. When True (default), all numerical denominator will be cleared;
when False the denominators will be cleared only if all terms had numerical
denominators other than 1.</p>
</div></blockquote>
<p><strong>fraction</strong> : bool, optional</p>
<blockquote>
<div><p>When True (default), will put the expression over a common
denominator.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core</span> <span class="kn">import</span> <span class="n">gcd_terms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span> <span class="o">+</span> <span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">y*(x + 1)*(x + y + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">(x + 2)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x/2 + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(x + y)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">)</span>
<span class="go">(x**2 + 2)/(2*x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">fraction</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(x + 2/x)/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">fraction</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x/2 + 1/x</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span><span class="o">/</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">)</span>
<span class="go">(x**2 + 2)/(2*x*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span><span class="o">/</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(x**2/2 + 1)/(x*y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gcd_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span><span class="o">/</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">/</span><span class="n">y</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">fraction</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(x/2 + 1/x)/y</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">clear</span></code> flag was ignored in this case because the returned
expression was a rational expression, not a simple sum.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.exprtools.factor_terms" title="sympy.core.exprtools.factor_terms"><code class="xref py py-obj docutils literal notranslate"><span class="pre">factor_terms</span></code></a>, <a class="reference internal" href="polys/reference.html#sympy.polys.polytools.terms_gcd" title="sympy.polys.polytools.terms_gcd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.terms_gcd</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="factor-terms">
<h3>factor_terms<a class="headerlink" href="#factor-terms" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.exprtools.factor_terms">
<span class="sig-prename descclassname"><span class="pre">sympy.core.exprtools.</span></span><span class="sig-name descname"><span class="pre">factor_terms</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">radical</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fraction</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sign</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/exprtools.py#L1163-L1274"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.exprtools.factor_terms" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove common factors from terms in all arguments without
changing the underlying structure of the expr. No expansion or
simplification (and no processing of non-commutatives) is performed.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>radical: bool, optional</strong></p>
<blockquote>
<div><p>If radical=True then a radical common to all terms will be factored
out of any Add sub-expressions of the expr.</p>
</div></blockquote>
<p><strong>clear</strong> : bool, optional</p>
<blockquote>
<div><p>If clear=False (default) then coefficients will not be separated
from a single Add if they can be distributed to leave one or more
terms with integer coefficients.</p>
</div></blockquote>
<p><strong>fraction</strong> : bool, optional</p>
<blockquote>
<div><p>If fraction=True (default is False) then a common denominator will be
constructed for the expression.</p>
</div></blockquote>
<p><strong>sign</strong> : bool, optional</p>
<blockquote>
<div><p>If sign=True (default) then even if the only factor in common is a -1,
it will be factored out of the expression.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factor_terms</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">x*(8*(2*y + 1)**3 + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">commutative</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">A</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">A</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">A</span><span class="p">)</span>
<span class="go">x*(y*A + 2*A)</span>
</pre></div>
</div>
<p>When <code class="docutils literal notranslate"><span class="pre">clear</span></code> is False, a rational will only be factored out of an
Add expression if all terms of the Add have coefficients that are
fractions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">x/2 + 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="n">x</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">(x + 2)/2</span>
</pre></div>
</div>
<p>If a -1 is all that can be factored out, to <em>not</em> factor it out, the
flag <code class="docutils literal notranslate"><span class="pre">sign</span></code> must be False:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="o">-</span><span class="n">x</span> <span class="o">-</span> <span class="n">y</span><span class="p">)</span>
<span class="go">-(x + y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="o">-</span><span class="n">x</span> <span class="o">-</span> <span class="n">y</span><span class="p">,</span> <span class="n">sign</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">-x - y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">factor_terms</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="n">sign</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">-2*(x + y)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.core.exprtools.gcd_terms" title="sympy.core.exprtools.gcd_terms"><code class="xref py py-obj docutils literal notranslate"><span class="pre">gcd_terms</span></code></a>, <a class="reference internal" href="polys/reference.html#sympy.polys.polytools.terms_gcd" title="sympy.polys.polytools.terms_gcd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.polys.polytools.terms_gcd</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="ordered">
<h3>ordered<a class="headerlink" href="#ordered" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.core.compatibility.ordered">
<span class="sig-prename descclassname"><span class="pre">sympy.core.compatibility.</span></span><span class="sig-name descname"><span class="pre">ordered</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">seq</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/compatibility.py#L501-L608"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.compatibility.ordered" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator of the seq where keys are used to break ties in
a conservative fashion: if, after applying a key, there are no ties
then no other keys will be computed.</p>
<p>Two default keys will be applied if 1) keys are not provided or 2) the
given keys don’t resolve all ties (but only if <code class="docutils literal notranslate"><span class="pre">default</span></code> is True). The
two keys are <code class="docutils literal notranslate"><span class="pre">_nodes</span></code> (which places smaller expressions before large) and
<code class="docutils literal notranslate"><span class="pre">default_sort_key</span></code> which (if the <code class="docutils literal notranslate"><span class="pre">sort_key</span></code> for an object is defined
properly) should resolve any ties.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">warn</span></code> is True then an error will be raised if there were no
keys remaining to break ties. This can be used if it was expected that
there should be no ties between items that are not identical.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.iterables</span> <span class="kn">import</span> <span class="n">ordered</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">count_ops</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<p>The count_ops is not sufficient to break ties in this list and the first
two items appear in their original order (i.e. the sorting is stable):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ordered</span><span class="p">([</span><span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">3</span><span class="p">],</span>
<span class="gp">... </span>   <span class="n">count_ops</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="gp">...</span>
<span class="go">[y + 2, x + 2, x**2 + y + 3]</span>
</pre></div>
</div>
<p>The default_sort_key allows the tie to be broken:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ordered</span><span class="p">([</span><span class="n">y</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">3</span><span class="p">]))</span>
<span class="gp">...</span>
<span class="go">[x + 2, y + 2, x**2 + y + 3]</span>
</pre></div>
</div>
<p>Here, sequences are sorted by length, then sum:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">seq</span><span class="p">,</span> <span class="n">keys</span> <span class="o">=</span> <span class="p">[[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">]],</span> <span class="p">[</span>
<span class="gp">... </span>   <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
<span class="gp">... </span>   <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">sum</span><span class="p">(</span><span class="n">x</span><span class="p">)]]</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ordered</span><span class="p">(</span><span class="n">seq</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">[[1], [2], [1, 2, 1], [0, 3, 1], [1, 1, 3]]</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">warn</span></code> is True, an error will be raised if there were not
enough keys to break ties:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ordered</span><span class="p">(</span><span class="n">seq</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">not enough keys to break ties</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The decorated sort is one of the fastest ways to sort a sequence for
which special item comparison is desired: the sequence is decorated,
sorted on the basis of the decoration (e.g. making all letters lower
case) and then undecorated. If one wants to break ties for items that
have the same decorated value, a second key can be used. But if the
second key is expensive to compute then it is inefficient to decorate
all items with both keys: only those items having identical first key
values need to be decorated. This function applies keys successively
only when needed to break ties. By yielding an iterator, use of the
tie-breaker is delayed as long as possible.</p>
<p>This function is best used in cases when use of the first key is
expected to be a good hashing function; if there are no unique hashes
from application of a key, then that key should not have been used. The
exception, however, is that even if there are many collisions, if the
first group is small and one does not need to process all items in the
list then time will not be wasted sorting what one was not interested
in. For example, if one were looking for the minimum in a list and
there were several criteria used to define the sort order, then this
function would be good at returning that quickly if the first group
of candidates is small relative to the number of items being processed.</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.core.kind">
<span id="kind"></span><h2>kind<a class="headerlink" href="#module-sympy.core.kind" title="Permalink to this headline">¶</a></h2>
<section id="id48">
<h3>Kind<a class="headerlink" href="#id48" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.core.kind.Kind">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.core.kind.</span></span><span class="sig-name descname"><span class="pre">Kind</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/core/kind.py#L48-L81"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.core.kind.Kind" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for kinds.</p>
<p>Kind of the object represents the mathematical classification that
the entity falls into. It is expected that functions and classes
recognize and filter the argument by its kind.</p>
<p>Kind of every object must be carefully selected so that it shows the
intention of design. Expressions may have different kind according
to the kind of its arguements. For example, arguements of <code class="docutils literal notranslate"><span class="pre">Add</span></code>
must have common kind since addition is group operator, and the
resulting <code class="docutils literal notranslate"><span class="pre">Add()</span></code> has the same kind.</p>
<p>For the performance, each kind is as broad as possible and is not
based on set theory. For example, <code class="docutils literal notranslate"><span class="pre">NumberKind</span></code> includes not only
complex number but expression containing <code class="docutils literal notranslate"><span class="pre">S.Infinity</span></code> or <code class="docutils literal notranslate"><span class="pre">S.NaN</span></code>
which are not strictly number.</p>
<p>Kind may have arguments as parameter. For example, <code class="docutils literal notranslate"><span class="pre">MatrixKind()</span></code>
may be constructed with one element which represents the kind of its
elements.</p>
<p><code class="docutils literal notranslate"><span class="pre">Kind</span></code> behaves in singleton-like fashion. Same signature will
return the same object.</p>
</dd></dl>

</section>
<section id="numberkind">
<h3>NumberKind<a class="headerlink" href="#numberkind" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.kind.NumberKind">
<span class="sig-prename descclassname"><span class="pre">sympy.core.kind.</span></span><span class="sig-name descname"><span class="pre">NumberKind</span></span><a class="headerlink" href="#sympy.core.kind.NumberKind" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of NumberKind</p>
</dd></dl>

</section>
<section id="booleankind">
<h3>BooleanKind<a class="headerlink" href="#booleankind" title="Permalink to this headline">¶</a></h3>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.core.kind.BooleanKind">
<span class="sig-prename descclassname"><span class="pre">sympy.core.kind.</span></span><span class="sig-name descname"><span class="pre">BooleanKind</span></span><a class="headerlink" href="#sympy.core.kind.BooleanKind" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of BooleanKind</p>
</dd></dl>

</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Core</a><ul>
<li><a class="reference internal" href="#module-sympy.core.sympify">sympify</a><ul>
<li><a class="reference internal" href="#id1">sympify</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.assumptions">assumptions</a><ul>
<li><a class="reference internal" href="#examples">Examples</a></li>
<li><a class="reference internal" href="#see-also">See Also</a></li>
<li><a class="reference internal" href="#notes">Notes</a></li>
<li><a class="reference internal" href="#developers-notes">Developers Notes</a></li>
<li><a class="reference internal" href="#references">References</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.cache">cache</a><ul>
<li><a class="reference internal" href="#cacheit">cacheit</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.basic">basic</a><ul>
<li><a class="reference internal" href="#id15">Basic</a></li>
<li><a class="reference internal" href="#atom">Atom</a></li>
</ul>
</li>
<li><a class="reference internal" href="#id16">core</a></li>
<li><a class="reference internal" href="#module-sympy.core.singleton">singleton</a><ul>
<li><a class="reference internal" href="#s">S</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.expr">expr</a><ul>
<li><a class="reference internal" href="#id17">Expr</a></li>
<li><a class="reference internal" href="#unevaluatedexpr">UnevaluatedExpr</a></li>
<li><a class="reference internal" href="#atomicexpr">AtomicExpr</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.symbol">symbol</a><ul>
<li><a class="reference internal" href="#id21">Symbol</a></li>
<li><a class="reference internal" href="#wild">Wild</a></li>
<li><a class="reference internal" href="#dummy">Dummy</a></li>
<li><a class="reference internal" href="#symbols">symbols</a></li>
<li><a class="reference internal" href="#var">var</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.numbers">numbers</a><ul>
<li><a class="reference internal" href="#number">Number</a></li>
<li><a class="reference internal" href="#float">Float</a></li>
<li><a class="reference internal" href="#rational">Rational</a></li>
<li><a class="reference internal" href="#integer">Integer</a></li>
<li><a class="reference internal" href="#numbersymbol">NumberSymbol</a></li>
<li><a class="reference internal" href="#realnumber">RealNumber</a></li>
<li><a class="reference internal" href="#igcd">igcd</a></li>
<li><a class="reference internal" href="#ilcm">ilcm</a></li>
<li><a class="reference internal" href="#seterr">seterr</a></li>
<li><a class="reference internal" href="#zero">Zero</a></li>
<li><a class="reference internal" href="#one">One</a></li>
<li><a class="reference internal" href="#negativeone">NegativeOne</a></li>
<li><a class="reference internal" href="#half">Half</a></li>
<li><a class="reference internal" href="#nan">NaN</a></li>
<li><a class="reference internal" href="#infinity">Infinity</a></li>
<li><a class="reference internal" href="#negativeinfinity">NegativeInfinity</a></li>
<li><a class="reference internal" href="#complexinfinity">ComplexInfinity</a></li>
<li><a class="reference internal" href="#exp1">Exp1</a></li>
<li><a class="reference internal" href="#imaginaryunit">ImaginaryUnit</a></li>
<li><a class="reference internal" href="#pi">Pi</a></li>
<li><a class="reference internal" href="#eulergamma">EulerGamma</a></li>
<li><a class="reference internal" href="#catalan">Catalan</a></li>
<li><a class="reference internal" href="#goldenratio">GoldenRatio</a></li>
<li><a class="reference internal" href="#tribonacciconstant">TribonacciConstant</a></li>
<li><a class="reference internal" href="#mod-inverse">mod_inverse</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.power">power</a><ul>
<li><a class="reference internal" href="#pow">Pow</a></li>
<li><a class="reference internal" href="#integer-nthroot">integer_nthroot</a></li>
<li><a class="reference internal" href="#integer-log">integer_log</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.mul">mul</a><ul>
<li><a class="reference internal" href="#id40">Mul</a></li>
<li><a class="reference internal" href="#prod">prod</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.add">add</a><ul>
<li><a class="reference internal" href="#id41">Add</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.mod">mod</a><ul>
<li><a class="reference internal" href="#id42">Mod</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.relational">relational</a><ul>
<li><a class="reference internal" href="#rel">Rel</a></li>
<li><a class="reference internal" href="#eq">Eq</a></li>
<li><a class="reference internal" href="#ne">Ne</a></li>
<li><a class="reference internal" href="#lt">Lt</a></li>
<li><a class="reference internal" href="#le">Le</a></li>
<li><a class="reference internal" href="#gt">Gt</a></li>
<li><a class="reference internal" href="#ge">Ge</a></li>
<li><a class="reference internal" href="#equality">Equality</a></li>
<li><a class="reference internal" href="#greaterthan">GreaterThan</a></li>
<li><a class="reference internal" href="#lessthan">LessThan</a></li>
<li><a class="reference internal" href="#unequality">Unequality</a></li>
<li><a class="reference internal" href="#strictgreaterthan">StrictGreaterThan</a></li>
<li><a class="reference internal" href="#strictlessthan">StrictLessThan</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.multidimensional">multidimensional</a><ul>
<li><a class="reference internal" href="#vectorize">vectorize</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.function">function</a><ul>
<li><a class="reference internal" href="#lambda">Lambda</a></li>
<li><a class="reference internal" href="#wildfunction">WildFunction</a></li>
<li><a class="reference internal" href="#derivative">Derivative</a></li>
<li><a class="reference internal" href="#diff">diff</a></li>
<li><a class="reference internal" href="#functionclass">FunctionClass</a></li>
<li><a class="reference internal" href="#id47">Function</a></li>
<li><a class="reference internal" href="#subs">Subs</a></li>
<li><a class="reference internal" href="#expand">expand</a></li>
<li><a class="reference internal" href="#poleerror">PoleError</a></li>
<li><a class="reference internal" href="#count-ops">count_ops</a></li>
<li><a class="reference internal" href="#expand-mul">expand_mul</a></li>
<li><a class="reference internal" href="#expand-log">expand_log</a></li>
<li><a class="reference internal" href="#expand-func">expand_func</a></li>
<li><a class="reference internal" href="#expand-trig">expand_trig</a></li>
<li><a class="reference internal" href="#expand-complex">expand_complex</a></li>
<li><a class="reference internal" href="#expand-multinomial">expand_multinomial</a></li>
<li><a class="reference internal" href="#expand-power-exp">expand_power_exp</a></li>
<li><a class="reference internal" href="#expand-power-base">expand_power_base</a></li>
<li><a class="reference internal" href="#nfloat">nfloat</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.evalf">evalf</a><ul>
<li><a class="reference internal" href="#evalfmixin">EvalfMixin</a></li>
<li><a class="reference internal" href="#precisionexhausted">PrecisionExhausted</a></li>
<li><a class="reference internal" href="#n">N</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.containers">containers</a><ul>
<li><a class="reference internal" href="#tuple">Tuple</a></li>
<li><a class="reference internal" href="#dict">Dict</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.compatibility">compatibility</a><ul>
<li><a class="reference internal" href="#iterable">iterable</a></li>
<li><a class="reference internal" href="#is-sequence">is_sequence</a></li>
<li><a class="reference internal" href="#as-int">as_int</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.exprtools">exprtools</a><ul>
<li><a class="reference internal" href="#gcd-terms">gcd_terms</a></li>
<li><a class="reference internal" href="#factor-terms">factor_terms</a></li>
<li><a class="reference internal" href="#ordered">ordered</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.core.kind">kind</a><ul>
<li><a class="reference internal" href="#id48">Kind</a></li>
<li><a class="reference internal" href="#numberkind">NumberKind</a></li>
<li><a class="reference internal" href="#booleankind">BooleanKind</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="concrete.html"
                        title="previous chapter">Concrete</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="crypto.html"
                        title="next chapter">Cryptography</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/core.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="crypto.html" title="Cryptography"
             >next</a> |</li>
        <li class="right" >
          <a href="concrete.html" title="Concrete"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Core</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/core.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:19 GMT -->
</html>